質問編集履歴
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -32,4 +32,32 @@
|
|
32
32
|
|
33
33
|
cash_register = Cash_register.new(customer_1)
|
34
34
|
cash_register.price
|
35
|
+
```
|
36
|
+
|
37
|
+
回答をいただき、変更したコードが以下になります。
|
38
|
+
```
|
39
|
+
class Cashier
|
40
|
+
ITEM = { 'apple' => 150, 'orange' => 100 }
|
41
|
+
|
42
|
+
def calc_item(ite)
|
43
|
+
p ite.map { |i| ITEM[i] }.sum
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
price = Cashier.new
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
class Customer
|
52
|
+
def initialize(*item)
|
53
|
+
p @item = item
|
54
|
+
end
|
55
|
+
|
56
|
+
def basket(p)
|
57
|
+
p.calc_item(@item)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
customer_1 = Customer.new('apple','orange')
|
62
|
+
customer_1.basket(price)
|
35
63
|
```
|