Sha256: 5af6a37052e56e3b74301ae7ddcd3da35de2f8ab949c5063dfe13dbe52c6b743

Contents?: true

Size: 495 Bytes

Versions: 3

Compression:

Stored size: 495 Bytes

Contents

#---
# Excerpted from "Agile Web Development with Rails, 2nd Ed."
# We make no guarantees that this code is fit for any purpose. 
# Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information.
#---
class CartItem
  
  attr_reader :product, :quantity
  
  def initialize(product)
    @product = product
    @quantity = 1
  end
  
  def increment_quantity
    @quantity += 1
  end
  
  def title
    @product.title
  end
  
  def price
    @product.price * @quantity
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
amrita2-2.0.0 sample/depot/app/models/cart_item.rb
amrita2-2.0.1 sample/depot/app/models/cart_item.rb
amrita2-2.0.2 sample/depot/app/models/cart_item.rb