master
1class Cart
2 def initialize(items = [])
3 @items = items
4 end
5
6 def add(product)
7 @items.push(product)
8 end
9
10 def includes?(product)
11 @items.include?(product)
12 end
13
14 def quantity_of(product)
15 @items.find_all do |item|
16 item == product
17 end.count
18 end
19
20 def total_items
21 @items.count
22 end
23
24 def total_price
25 @items.reduce(Money.new(0.00)) do |total, item|
26 total + item.price
27 end
28 end
29end