Class: Money::Base
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(other) ⇒ Object
- #<=>(other) ⇒ Object
- #convert_to(to_curr) ⇒ Object
-
#initialize(amount, currency) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
Constructor Details
#initialize(amount, currency) ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/money/base.rb', line 7 def initialize(amount, currency) @amount, @currency = amount, currency end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
5 6 7 |
# File 'lib/money/base.rb', line 5 def amount @amount end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
5 6 7 |
# File 'lib/money/base.rb', line 5 def currency @currency end |
Instance Method Details
#*(other) ⇒ Object
31 32 33 |
# File 'lib/money/base.rb', line 31 def *(other) arith(:*, other) end |
#+(other) ⇒ Object
23 24 25 |
# File 'lib/money/base.rb', line 23 def +(other) arith(:+, other) end |
#-(other) ⇒ Object
27 28 29 |
# File 'lib/money/base.rb', line 27 def -(other) arith(:-, other) end |
#/(other) ⇒ Object
35 36 37 |
# File 'lib/money/base.rb', line 35 def /(other) arith(:/, other) end |
#<=>(other) ⇒ Object
19 20 21 |
# File 'lib/money/base.rb', line 19 def <=>(other) @amount <=> other.convert_to(@currency).amount end |
#convert_to(to_curr) ⇒ Object
15 16 17 |
# File 'lib/money/base.rb', line 15 def convert_to(to_curr) self.class.new(convert(to_curr), to_curr) end |
#inspect ⇒ Object
11 12 13 |
# File 'lib/money/base.rb', line 11 def inspect "#{@amount} #{@currency}" end |