David Chelimsky
10/6/2006 11:29:00 AM
On 10/5/06, Ohad Lutzky <lutzky@gmail.com> 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
One of the beauties of the language (for me) is that language
invariants become somewhat less "in" and more "variant".