From: David Chelimsky Date: 2006-10-06T23:22:50+09:00 Subject: Re: nil being empty On 10/6/06, dblack@wobblini.net wrote: > Hi -- > > On Fri, 6 Oct 2006, David Chelimsky wrote: > > > On 10/5/06, Ohad Lutzky wrote: > >> Show of hands - who thinks this is bad form? > >> > >> class NilClass > >> def empty?; true; end > >> end > > > > Doesn't it depend on context? The other responders seem to suggest > > that is objectively bad form, with which I can agree (generally), but > > in a case like this: > > > > collection.select do |item| > > item.respond_to?(:empty?) and (!item.empty?) > > end > > > > I might prefer > > > > collection.select do |item| > > true unless item.empty? > > end > > > > or this (which, though more terse, I personally find less readable) > > > > collection.select do |item| > > !item.empty? > > end > > (Don't forget Enumerable#reject :-) collection.reject do |item| item.empty? end much better, indeed! Jeez, I love this language.