Skip to content

Instantly share code, notes, and snippets.

@joeljunstrom
Created May 13, 2011 13:13
Show Gist options
  • Save joeljunstrom/970511 to your computer and use it in GitHub Desktop.
Save joeljunstrom/970511 to your computer and use it in GitHub Desktop.
class Sku
attr_reader :identifier
attr_reader :price
end
class Cart
many :cart_items
def quantity
cart_items.inject(0) { |quantity, item| quantity += item.quantity }
end
def sum
cart_items.inject(0) { |sum, item| sum += item.sum }
end
end
class CartItem
belongs_to :sku
attr_reader :quantity
def sum
quantity * sku.price
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment