From: Dirk Traulsen Date: 2007-10-18T03:27:36+09:00 Subject: Re: nil.to_i returning zero Am 17 Oct 2007 um 21:08 hat Robert Dober geschrieben: > On 10/17/07, Dirk Traulsen wrote: > > > I think this is a reasonable proposal: > > > > class NilClass > > def +(obj) > > obj > > end > > end > > > > Can you think of any case in which this poses a problem? > > Hmm, let me see > a = [42] > b += a > b << [43] ouch that hurts > > maybe > class NilClass > def + obj > obj.clone rescue obj > end > end You're right. That's really better. (You didn't have to look too hard for a problem, did you? :) Sometimes I'm blind! ) But in earnest, I really think this would be a good thing to have in Ruby. I'm not so sure about the other cases *,- and /. There you would have to make a not so short list of object classes for which they must be handled differently. But not for +, there it is very clear: nothing + x is always x, independant from the nature of x. So, as this is universally correct, it could go in Ruby itself.