summaryrefslogtreecommitdiff
path: root/lib/cart.rb
blob: 1bfe56221299e78c38e90ecb4a9f199e74e7d6fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Cart
  def initialize(items = [])
    @items = items
  end

  def add(product)
    @items.push(product)
  end

  def includes?(product)
    @items.include?(product)
  end

  def quantity_of(product)
    @items.find_all do |item|
      item == product
    end.count
  end

  def total_items
    @items.count
  end
end