From: Eric LIn Date: 2008-10-02T05:49:09+09:00 Subject: Re: Bug in the money gem? On Sep 25, 12:04 pm, Michael Guterl wrote: > On Thu, Sep 25, 2008 at 2:34 PM, Eric LIn wrote: > > For anyone of you using the money gem (http://dist.leetsoft.com/api/ > > money/), I noticed today that 0 - 100 does not equal -100, it equals > > 100 instead (all numbers here represent Money objects).  Do any of you > > find that odd? > > I'm not sure, but it seems a bit strange.  Here is the offending code: > >     # File lib/money/money.rb, line 79 > 79:   def -(other_money) > 80:     return other_money.dup if cents.zero? > 81:     return dup if other_money.cents.zero? > 82: > 83:     if self.cents == 0 or currency == other_money.currency > 84:       Money.new(cents - other_money.cents, other_money.currency) > 85:     else > 86:       Money.new(cents - other_money.exchange_to(currency).cents, currency) > 87:     end > 88:   end > > I think the first return would make sense if the other_money variable > had a negative value associated with it, however, other_money's value > is not negative. > > HTH, > Michael Guterl Thanks for the response, I figured that's the problem too. It seems the author made the mistake unintentionally, when he copies that line of code from the "+" method. Thanks for confirming my suspicion; I was thinking maybe it's something in currency arithmetic that I don't understand. I've emailed the author, but so far no response.