Class: MoneyExchange::Money

Inherits:
Object
  • Object
show all
Defined in:
lib/money_exchange.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount, currency) ⇒ Money

Returns a new instance of 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

#amountObject (readonly)

Returns the value of attribute amount.



24
25
26
# File 'lib/money_exchange.rb', line 24

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



24
25
26
# File 'lib/money_exchange.rb', line 24

def currency
  @currency
end