質問編集履歴

1

追記

2020/04/02 12:34

投稿

jpj
jpj

スコア27

test CHANGED
File without changes
test CHANGED
@@ -67,3 +67,59 @@
67
67
  cash_register.price
68
68
 
69
69
  ```
70
+
71
+
72
+
73
+ 回答をいただき、変更したコードが以下になります。
74
+
75
+ ```
76
+
77
+ class Cashier
78
+
79
+ ITEM = { 'apple' => 150, 'orange' => 100 }
80
+
81
+
82
+
83
+ def calc_item(ite)
84
+
85
+ p ite.map { |i| ITEM[i] }.sum
86
+
87
+ end
88
+
89
+ end
90
+
91
+
92
+
93
+ price = Cashier.new
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+ class Customer
102
+
103
+ def initialize(*item)
104
+
105
+ p @item = item
106
+
107
+ end
108
+
109
+
110
+
111
+ def basket(p)
112
+
113
+ p.calc_item(@item)
114
+
115
+ end
116
+
117
+ end
118
+
119
+
120
+
121
+ customer_1 = Customer.new('apple','orange')
122
+
123
+ customer_1.basket(price)
124
+
125
+ ```