Created
May 13, 2011 13:13
-
-
Save joeljunstrom/970511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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