Method: Finance::Rate#initialize
- Defined in:
- lib/finance/rates.rb
#initialize(rate, type, opts = {}) ⇒ Rate
create a new Rate instance
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/finance/rates.rb', line 90 def initialize(rate, type, opts={}) # Default monthly compounding. opts = { :compounds => :monthly }.merge opts # Set optional attributes.. opts.each do |key, value| send("#{key}=", value) end # Set the rate in the proper way, based on the value of type. begin send("#{TYPES.fetch(type)}=", rate.to_d) rescue KeyError raise ArgumentError, "type must be one of #{TYPES.keys.join(', ')}", caller end end |