Files
ruby-checkout/shop.rb
T
David Underwood 882c18b5e6 Rebuild the Checkout class, no discounts yet
Checkout now stores its items using a quantity and a link back to the
original product instance. It has a reference to the store to make sure
that product IDs added are valid
2026-07-21 10:27:33 -04:00

21 lines
353 B
Ruby

class Shop
class DuplicateProductIdError < StandardError; end
def initialize
@products = []
end
def products
@products
end
def add_product(product)
raise DuplicateProductIdError if product_by_id(product.id)
@products.push(product)
end
def product_by_id(id)
@products.find { |product| product.id == id }
end
end