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
This commit is contained in:
David Underwood
2026-07-21 10:27:33 -04:00
parent e570783935
commit 882c18b5e6
4 changed files with 91 additions and 58 deletions
+3 -5
View File
@@ -9,14 +9,12 @@ class Shop
end
def add_product(product)
raise DuplicateProductIdError if duplicate_id?(product.id)
raise DuplicateProductIdError if product_by_id(product.id)
@products.push(product)
end
private
def duplicate_id?(id)
@products.map(&:id).include?(id)
def product_by_id(id)
@products.find { |product| product.id == id }
end
end