Module: BigMoney::Exchangeable

Included in:
BigMoney
Defined in:
lib/big_money/exchange.rb

Overview

Synopsis

require 'big_money'
require 'big_money/exchange/yahoo' # Use yahoo finance exchange service.

bm = BigMoney.new('3.99', :usd)
bm.amount   #=> BigDecimal.new('3.99')
bm.currency #=> BigMoney::Currency::USD

bm2 = bm.exchange(:aud)
bm.amount   #=> BigDecimal.new('5.22')
bm.currency #=> BigMoney::Currency::AUD

Instance Method Summary collapse

Instance Method Details

#exchange(to) ⇒ Object

Exchange to a new Currency.

Examples

BigMoney.new(12.50, :aud).exchange(:usd)

Parameters

from<BigMoney::Currency, #to_s>

Anything that BigMoney::Currency#find can find.

Returns

BigMoney



30
31
32
33
# File 'lib/big_money/exchange.rb', line 30

def exchange(to)
  ex = amount * Exchange.rate(currency, to)
  self.class.new(ex, to)
end