Permalink
Browse files

fix arithmetic comparison with numeric

  • Loading branch information...
kristianmandrup committed May 17, 2012
1 parent c823fc9 commit 3d7e64c8a45f07780d560303e61ccbce119ee18b
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/money/money/arithmetic.rb
@@ -40,25 +40,25 @@ def ==(other_money)
#
# @see #==
def eql?(other_money)
- if other_money.respond_to?(:to_money)
- self == other_money
- elsif other_money.kind_of? Numeric
+ if other_money.kind_of? Numeric
self == Money.new(other_money)
+ elsif other_money.respond_to?(:to_money)
+ self == other_money
else
false
end
end
def <=>(other_money)
- if other_money.respond_to?(:to_money)
+ if other_money.kind_of? Numeric
+ cents <=> Money.new(other_money).cents
+ elsif other_money.respond_to?(:to_money)
other_money = other_money.to_money
if self.currency == other_money.currency
cents <=> other_money.cents
else
cents <=> other_money.exchange_to(currency).cents
end
- elsif other_money.kind_of? Numeric
- cents <=> Money.new(other).cents
else
raise ArgumentError, "Comparison of #{self.class} with #{other_money.inspect} failed"
end

0 comments on commit 3d7e64c

Please sign in to comment.