Class: Hola::Product::Inventory
- Inherits:
-
Object
- Object
- Hola::Product::Inventory
- Includes:
- Singleton
- Defined in:
- lib/hola/product/inventory.rb
Instance Attribute Summary collapse
-
#products ⇒ Object
readonly
Returns the value of attribute products.
Instance Method Summary collapse
- #find_product(id) ⇒ Object
-
#initialize ⇒ Inventory
constructor
A new instance of Inventory.
Constructor Details
#initialize ⇒ Inventory
Returns a new instance of Inventory.
17 18 19 20 21 22 23 |
# File 'lib/hola/product/inventory.rb', line 17 def initialize @products = [ Product.new(name: "Green Tea", price: 3.11, offer: "GetOneFree"), Product.new(name: "Strawberries", price: 5.0, offer: "StrawberryBulkDiscount"), Product.new(name: "Coffee", price: 11.23, offer: "TwoThirdsBulkDiscount") ] end |
Instance Attribute Details
#products ⇒ Object (readonly)
Returns the value of attribute products.
15 16 17 |
# File 'lib/hola/product/inventory.rb', line 15 def products @products end |
Instance Method Details
#find_product(id) ⇒ Object
25 26 27 |
# File 'lib/hola/product/inventory.rb', line 25 def find_product(id) products.find { |p| p.id == id } end |