Created
May 27, 2016 17:52
-
-
Save sicktastic/ab1bf198932b084226d5b7f7acc59e64 to your computer and use it in GitHub Desktop.
Excerise from Upcase: https://exercises.upcase.com/exercises/replace-variable-with-query
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 Tipper | |
TAX = 0.05 | |
def initializer(amount:, discount_percentage: 0, tip_percentage:) | |
@amount = amount | |
@discount_percentage = discount_percentage | |
@tip_percentage = tip_percentage | |
end | |
def total | |
amount + tax_amount - discount_amount + tip_amount | |
end | |
private | |
def tax_amount | |
amount + TAX | |
end | |
def discount_amount | |
amount * (discount_percentage / 100.0) | |
end | |
def tip_amount | |
amount * (tip_percentage / 100.0) | |
end | |
attr_reader :amount, :discount_percentage, :tip_percentage | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment