From: Farrel Lifson Date: 2006-10-06T21:30:21+09:00 Subject: Re: nil being empty On 06/10/06, David Chelimsky wrote: > 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 > > One of the beauties of the language (for me) is that language > invariants become somewhat less "in" and more "variant". > > You could make it slightly more elegant with an extra function call collection.select.do |item| !Array(item).empty? #Could also use !String(item).empty depending on what item is end Farrel