I've written a very basic finance module in Ruby to ease my own calculations, as sometimes it's just a lot easier to enter irb
and start calling functions. But the odd thing is, that in my module I have a submodule with a method called future_value (Finance::CompoundInterest.future_value
) ... but according to irb
it doesn't exist? It's quite small, but I'd really prefer to be able to use compound interest instead of having to enter the formula each time.
When loading in irb
no errors or warnings are thrown, and the method is invisible for all intents and purposes. Almost sadly, I can instantiate a Finance::Mortgage
.
Here's my finance unit:
module Finance
module CompoundInterest
def future_value(present_value, interest, length)
interest /= 100 if interest >= 1 # if given in percent 1..100
present_value * ((1 + interest)**length)
end
end
class Mortgage
attr_accessor :amount, :rate, :years, :payment, :interest_paid
def initialize(amount, rate, years)
@amount, @rate, @years = amount, rate, years
i = rate / 12
n = years * 12
m = (1 + i)**n
@payment = ((i * m) / (m - 1)) * amount
@interest_paid = @payment * n - amount
end
end
end
What have I mistyped to get this strange situation? I am using Ruby 1.8.7-72.