Skip to content

Instantly share code, notes, and snippets.

@sicktastic
Created May 27, 2016 17:52
Show Gist options
  • Save sicktastic/ab1bf198932b084226d5b7f7acc59e64 to your computer and use it in GitHub Desktop.
Save sicktastic/ab1bf198932b084226d5b7f7acc59e64 to your computer and use it in GitHub Desktop.
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