質問編集履歴
4
your_hand→you_hand
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,7 +37,7 @@
|
|
37
37
|
puts "あなたの手:#{jankens[you_hand]}, プログラムの手:#{jankens[program_hand]}"
|
38
38
|
|
39
39
|
|
40
|
-
if
|
40
|
+
if you_hand == program_hand
|
41
41
|
puts "あいこで"
|
42
42
|
return true
|
43
43
|
elsif (you_hand == 0 && program_hand == 1) ||
|
3
前提の編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
|
4
4
|
ここに質問の内容を詳しく書いてください。
|
5
5
|
Rubyを勉強し始め、じゃんけんアプリを作っております。
|
6
|
+
classを使用しての書き換えです。
|
6
7
|
通常の関数によるじゃんけんアプリの作成は、ネットの記事で理解しました。(https://qiita.com/aiorange19/items/dff465f9e7af5e996f13)
|
7
|
-
classを使用して作成しておりますが、どうしてもわからないです。
|
8
|
-
他のクラスへのアクセス自体ができていない、もしくは設計自体がおかしいのか。。
|
9
8
|
|
10
9
|
ご教示頂けないでしょうか。どうぞ宜しくお願い致します。
|
11
10
|
|
@@ -20,7 +19,6 @@
|
|
20
19
|
```Ruby
|
21
20
|
class You
|
22
21
|
def hand
|
23
|
-
|
24
22
|
puts "[0]グー\n[1]チョキ\n[2]パー"
|
25
23
|
you_hand = gets.to_i
|
26
24
|
|
2
you_handに統一
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
def hand
|
23
23
|
|
24
24
|
puts "[0]グー\n[1]チョキ\n[2]パー"
|
25
|
-
|
25
|
+
you_hand = gets.to_i
|
26
26
|
|
27
27
|
end
|
28
28
|
end
|
@@ -34,17 +34,17 @@
|
|
34
34
|
end
|
35
35
|
|
36
36
|
class Janken
|
37
|
-
def pon(
|
37
|
+
def pon(you_hand, program_hand)
|
38
38
|
jankens = ["グー", "チョキ", "パー"]
|
39
|
-
puts "あなたの手:#{jankens[
|
39
|
+
puts "あなたの手:#{jankens[you_hand]}, プログラムの手:#{jankens[program_hand]}"
|
40
40
|
|
41
41
|
|
42
42
|
if your_hand == program_hand
|
43
43
|
puts "あいこで"
|
44
44
|
return true
|
45
|
-
elsif (
|
45
|
+
elsif (you_hand == 0 && program_hand == 1) ||
|
46
|
-
(
|
46
|
+
(you_hand == 1 && program_hand == 2) ||
|
47
|
-
(
|
47
|
+
(you_hand == 2 && program_hand == 0)
|
48
48
|
puts "あなたの勝ちです"
|
49
49
|
return false
|
50
50
|
else
|
1
your_hand, program_handに変数名を修正し、統一しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
def hand
|
23
23
|
|
24
24
|
puts "[0]グー\n[1]チョキ\n[2]パー"
|
25
|
-
|
25
|
+
your_hand = gets.to_i
|
26
26
|
|
27
27
|
end
|
28
28
|
end
|
@@ -34,15 +34,17 @@
|
|
34
34
|
end
|
35
35
|
|
36
36
|
class Janken
|
37
|
-
def pon(
|
37
|
+
def pon(your_hand, program_hand)
|
38
38
|
jankens = ["グー", "チョキ", "パー"]
|
39
|
-
puts "あなたの手:#{jankens[
|
39
|
+
puts "あなたの手:#{jankens[your_hand]}, プログラムの手:#{jankens[program_hand]}"
|
40
40
|
|
41
41
|
|
42
|
-
if
|
42
|
+
if your_hand == program_hand
|
43
43
|
puts "あいこで"
|
44
44
|
return true
|
45
|
-
elsif (
|
45
|
+
elsif (your_hand == 0 && program_hand == 1) ||
|
46
|
+
(your_hand == 1 && program_hand == 2) ||
|
47
|
+
(your_hand == 2 && program_hand == 0)
|
46
48
|
puts "あなたの勝ちです"
|
47
49
|
return false
|
48
50
|
else
|