回答編集履歴

1

追記

2019/11/30 09:21

投稿

asm
asm

スコア15149

test CHANGED
@@ -5,6 +5,14 @@
5
5
 
6
6
 
7
7
  ```ruby
8
+
9
+ def initialize
10
+
11
+ @movies = []
12
+
13
+ end
14
+
15
+
8
16
 
9
17
  def post
10
18
 
@@ -17,3 +25,69 @@
17
25
  end
18
26
 
19
27
  ```
28
+
29
+
30
+
31
+ ---
32
+
33
+
34
+
35
+ 別解
36
+
37
+
38
+
39
+ ```ruby
40
+
41
+ # ハッシュでやる場合
42
+
43
+ def post
44
+
45
+ title=gets.chomp
46
+
47
+ star=gets.to_i
48
+
49
+ @movies[title] = star
50
+
51
+ end
52
+
53
+ ```
54
+
55
+
56
+
57
+ ```ruby
58
+
59
+ # ハッシュの配列でやる場合
60
+
61
+ def initialize
62
+
63
+ @movies = []
64
+
65
+ end
66
+
67
+
68
+
69
+ def post
70
+
71
+ title=gets.chomp
72
+
73
+ star=gets.to_i
74
+
75
+ @movies << {title: title, star: star}
76
+
77
+ end
78
+
79
+
80
+
81
+ def show_review
82
+
83
+ @movies.each do |movie|
84
+
85
+ puts "タイトル#{movie[:title]}"
86
+
87
+ puts "五段階評価#{movie[:star]}"
88
+
89
+ end
90
+
91
+ end
92
+
93
+ ```