Skip to content

Instantly share code, notes, and snippets.

@counterbeing
Created January 8, 2021 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save counterbeing/0f96a36c013381975f747ace1248c386 to your computer and use it in GitHub Desktop.
Save counterbeing/0f96a36c013381975f747ace1248c386 to your computer and use it in GitHub Desktop.
class Calculator
DAYS_PER_YEAR=365
attr_accessor :years, :rate, :amount
def initialize(years, amount, rate)
@years = years
@rate = rate/100.0
@amount = amount
end
def calculate
(0..days).reduce(amount) do |acc|
(daily_interest_rate * acc) + acc
end
end
private
def days
years * DAYS_PER_YEAR
end
def daily_interest_rate
rate/DAYS_PER_YEAR
end
end
puts Calculator.new(1, 5000, 70).calculate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment