class Money::Base
Attributes
amount[R]
currency[R]
Public Class Methods
new(amount, currency)
click to toggle source
# File lib/money/base.rb, line 7 def initialize(amount, currency) @amount, @currency = amount, currency end
Public Instance Methods
*(other)
click to toggle source
# File lib/money/base.rb, line 31 def *(other) arith(:*, other) end
+(other)
click to toggle source
# File lib/money/base.rb, line 23 def +(other) arith(:+, other) end
-(other)
click to toggle source
# File lib/money/base.rb, line 27 def -(other) arith(:-, other) end
/(other)
click to toggle source
# File lib/money/base.rb, line 35 def /(other) arith(:/, other) end
<=>(other)
click to toggle source
# File lib/money/base.rb, line 19 def <=>(other) @amount <=> other.convert_to(@currency).amount end
convert_to(to_curr)
click to toggle source
# File lib/money/base.rb, line 15 def convert_to(to_curr) self.class.new(convert(to_curr), to_curr) end
inspect()
click to toggle source
# File lib/money/base.rb, line 11 def inspect "#{@amount} #{@currency}" end
Private Instance Methods
arith(op, obj)
click to toggle source
# File lib/money/base.rb, line 41 def arith(op, obj) if obj.is_a?(Money::Base) arith op, obj.convert_to(@currency).amount else @amount = @amount.send(op, obj) end self end
conversions()
click to toggle source
# File lib/money/base.rb, line 63 def conversions Money.configuration.conversions end
convert(to_curr)
click to toggle source
# File lib/money/base.rb, line 55 def convert(to_curr) convert_to_default_currency / conversions[to_curr] end
convert_to_default_currency()
click to toggle source
# File lib/money/base.rb, line 51 def convert_to_default_currency @amount * conversions[@currency] end
default_currency()
click to toggle source
# File lib/money/base.rb, line 59 def default_currency Money.configuration.default_currency end