Created
May 3, 2013 01:53
-
-
Save BrayanZ/5506721 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Invoice | |
def initialize *lines | |
@lines = lines | |
end | |
def total | |
@lines.inject(0){ |subtotal, line| subtotal += line_subtotal(line) } | |
end | |
def line_subtotal line | |
line[:quantity] * line[:price] | |
end | |
end | |
invoice = Invoice.new({quantity: 3, product_name: "ice tea", price: 300}, {quantity: 2, product_name: "Coca Cola", price: 1500}) | |
print invoice.total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment