money 1.4 → 1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/bank/no_exchange_bank.rb +1 -0
- data/lib/money/money.rb +4 -4
- metadata +2 -2
@@ -1,6 +1,7 @@
|
|
1
1
|
class NoExchangeBank# :nodoc:
|
2
2
|
|
3
3
|
def reduce(money, currency)
|
4
|
+
return money if money.currency == currency
|
4
5
|
raise Money::MoneyError.new("Current Money::bank does not support money exchange. Please implement a bank object that does and assign it to the Money class.")
|
5
6
|
end
|
6
7
|
|
data/lib/money/money.rb
CHANGED
@@ -66,16 +66,16 @@ class Money
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def +(other_money)
|
69
|
-
if currency == other_money.currency
|
70
|
-
Money.new(cents + other_money.cents,currency)
|
69
|
+
if self.cents == 0 or currency == other_money.currency
|
70
|
+
Money.new(cents + other_money.cents, other_money.currency)
|
71
71
|
else
|
72
72
|
Money.new(cents + other_money.exchange_to(currency).cents,currency)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
def -(other_money)
|
77
|
-
if currency == other_money.currency
|
78
|
-
Money.new(cents - other_money.cents, currency)
|
77
|
+
if self.cents == 0 or currency == other_money.currency
|
78
|
+
Money.new(cents - other_money.cents, other_money.currency)
|
79
79
|
else
|
80
80
|
Money.new(cents - other_money.exchange_to(currency).cents, currency)
|
81
81
|
end
|
metadata
CHANGED