lib/danconia/money.rb in danconia-0.2.7 vs lib/danconia/money.rb in danconia-0.2.8
- old
+ new
@@ -43,21 +43,21 @@
def <=> other
other = other.exchange_to(currency).amount if other.is_a? Money
amount <=> other
end
- def exchange_to other_currency
+ def exchange_to other_currency, exchange: @exchange
other_currency = other_currency.presence && Currency.find(other_currency, exchange) || currency
rate = exchange.rate currency.code, other_currency.code
- clone_with amount * rate, other_currency
+ clone_with amount * rate, other_currency, exchange
end
%w(+ - * /).each do |op|
class_eval <<-EOR, __FILE__, __LINE__ + 1
def #{op} other
- other = other.exchange_to(currency).amount if other.is_a? Money
- clone_with amount #{op} other
+ other = other.exchange_to(currency, exchange: @exchange).amount if other.is_a? Money
+ clone_with(amount #{op} other)
end
EOR
end
def round *args
@@ -92,10 +92,10 @@
def parse object
BigDecimal(object.to_s) rescue BigDecimal(0)
end
- def clone_with amount, currency = @currency
+ def clone_with amount, currency = @currency, exchange = @exchange
Money.new amount, currency, decimals: decimals, exchange: exchange
end
end
end