From: Austin Ziegler Date: 2005-08-10T21:49:40+09:00 Subject: Re: NEWBIE QUESTION: pattern with nil On 8/10/05, BearItAll wrote: > On Wed, 10 Aug 2005 14:44:15 +0900, John Carter wrote: > > class NilClass > > def empty? > > true > > end > > end > > if a.empty? > I vote for this one because a good programmer is a lazy sod. Where ever > you would end up doing a thing more than once, write it is such a way that > you never have to type it again. Just, please, don't do it in a library that you unleash on the rest of the world. It changes the contract for +nil+, and I prefer that it *not* respond to #empty?, because the concept isn't *quite* accurate. One may as well define #zero? if you're going to to that (but +nil+ isn't zero, either, just as it isn't the empty string or array). Better is to use the foo.nil? or foo.empty? construct and be explicit, or foo.to_s.empty? if you want to silently cast ("normalize"). Changing nil to respond to #empty? is an implicit change that also changes its meaning. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca