From: Alex Fenton Date: 2006-02-09T03:18:21+09:00 Subject: Re: boolean annoyance Claudio Jeker wrote: > Hello, > > there is one thing in ruby that annoys me most (at least for now). > > if 0 > puts "true" > end class Person def number_of_children() @children.length end def has_children?() @children.length > 0 end end In this context, like most others from a high-level language perspective, 0 is a valid meaningful value. If you *don't know* how many children a Person's got, return nil. If you *know* a Person hasn't got any return 0. Make a boolean-esque method if you want boolean values. As said in other replies and in the innumerable previous threads on this topic, 0's falsity is an implementation oddity of *some* languages. It used to create subtle bugs in my Perl code more often than it was a useful shortcut. Understanding why you need 'if ($value)' sometimes and 'if (defined $value)' other times is much more complicated than Ruby's solution. alex