Class: MoneyExchange::Money
- Inherits:
-
Object
- Object
- MoneyExchange::Money
- Defined in:
- lib/money_exchange.rb
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
-
#initialize(amount, currency) ⇒ Money
constructor
A new instance of Money.
- #method_missing(meth, *a, &b) ⇒ Object
Constructor Details
#initialize(amount, currency) ⇒ Money
25 26 27 28 |
# File 'lib/money_exchange.rb', line 25 def initialize(amount, currency) @amount = Float(amount) @currency = currency end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *a, &b) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/money_exchange.rb', line 30 def method_missing(meth, *a, &b) case meth when /^to_([a-z]{3})$/ Exchange.calc(self, $~[1]) else super end end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
24 25 26 |
# File 'lib/money_exchange.rb', line 24 def amount @amount end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
24 25 26 |
# File 'lib/money_exchange.rb', line 24 def currency @currency end |