Boy2Man 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Boy2Man.rb +12 -3
- data/lib/Boy2Man/version.rb +1 -1
- data/test/test_Boy2Man.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe8409cb3b5a4c95cb050b83c4ab25002a399a8a
|
4
|
+
data.tar.gz: f6df36a22794641a1e54cad2787bd1b94f7cbd71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 116dd50cfd17a702ecd6f0cb18706ee24d157e21db3dc38fd47d7f245bdd4acc18601c8b74ce10b7e951e5f6967f0996c8785fedf9f6e249b4ac73e2bb4b9eb5
|
7
|
+
data.tar.gz: e7375f8243412dfd702c0f4902e38345732074d2d5f81b7290976c05085824304689b85299ba33f62eb8d449cbe078826876ef083b1ddba99040c559436a74f4
|
data/lib/Boy2Man.rb
CHANGED
@@ -14,6 +14,8 @@ module Boy2Man
|
|
14
14
|
exit
|
15
15
|
when "グー\n", "チョキ\n", "パー\n"
|
16
16
|
puts stand.match(hand.chomp)
|
17
|
+
when "history\n"
|
18
|
+
puts stand.history
|
17
19
|
else
|
18
20
|
puts stand.select_hand
|
19
21
|
end
|
@@ -21,8 +23,15 @@ module Boy2Man
|
|
21
23
|
end
|
22
24
|
|
23
25
|
class Boy2Man
|
26
|
+
attr_reader :history
|
27
|
+
|
24
28
|
def initialize
|
25
|
-
@
|
29
|
+
@history = Array.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def history
|
33
|
+
# retrun deep copy of history, to prevent history to be changed.
|
34
|
+
Marshal.load(Marshal.dump(@history))
|
26
35
|
end
|
27
36
|
|
28
37
|
def match(hand)
|
@@ -30,7 +39,7 @@ module Boy2Man
|
|
30
39
|
when "グー", "チョキ", "パー"
|
31
40
|
# 先に手を決めておかないと後出しになる
|
32
41
|
selected = select_hand
|
33
|
-
@
|
42
|
+
@history.push hand
|
34
43
|
selected
|
35
44
|
else
|
36
45
|
end
|
@@ -46,7 +55,7 @@ module Boy2Man
|
|
46
55
|
|
47
56
|
private
|
48
57
|
def predict
|
49
|
-
@
|
58
|
+
@history.empty? ? %w(グー チョキ パー).sample : @history.sample
|
50
59
|
end
|
51
60
|
end
|
52
61
|
end
|
data/lib/Boy2Man/version.rb
CHANGED
data/test/test_Boy2Man.rb
CHANGED
@@ -14,4 +14,17 @@ class TestBoy2Man < MiniTest::Unit::TestCase
|
|
14
14
|
assert_includes ["グー", "チョキ", "パー"], @stand.select_hand
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
def test_history
|
19
|
+
assert_respond_to @stand, :history
|
20
|
+
assert_raises(NoMethodError) {
|
21
|
+
@stand.history = ['something']
|
22
|
+
}
|
23
|
+
|
24
|
+
assert_equal([], @stand.history)
|
25
|
+
@stand.match("グー")
|
26
|
+
assert_equal(["グー"], @stand.history)
|
27
|
+
@stand.match("チョキ")
|
28
|
+
assert_equal(["グー", "チョキ"], @stand.history)
|
29
|
+
end
|
17
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Boy2Man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zakuni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|