Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/currency_exchange/ext/fixnum.rb

Constant Summary collapse

UNABLE_TO_EXCHANGE =
"Unable to exchange"

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/currency_exchange/ext/fixnum.rb', line 9

def method_missing(sym, *args, &block)
  empty, from, to =  currency_string(sym)
  if CurrencyExchange.has_currency?(from, to)
    return exchange(from, to)
  else
    super.method_missing(sym, *args, &block)
  end
end

Instance Method Details

#exchange(from, to) ⇒ Object



4
5
6
7
# File 'lib/currency_exchange/ext/fixnum.rb', line 4

def exchange(from, to)
  exchange = CurrencyExchange.convert(self, from, to)
  exchange ? "$%.2f" % exchange : UNABLE_TO_EXCHANGE
end