I just thought I would add to the history of zero being false in C. C was 
designed to be compiler friendly. Most every processor has a branch if zero 
machine instruction that is used for loops. It is convenient therefore to 
use a zero value as a Boolean conditional for a branch. It creates denser 
code.

Strictly speaking, binary 0 is not Boolean false. It is simply a convention 
that some have chosen. In electronics it is very common to have binary 0 
mean Boolean true and 1 mean false.

"Claudio Jeker" <cjeker / diehard.n-r-g.com> wrote in message 
news:20060208152543.GA16920 / diehard.n-r-g.com...
> Hello,
>
> there is one thing in ruby that annoys me most (at least for now).
>
> if 0
> puts "true"
> end
>
> Yes, I know everything expect nil and false are true but that's probably
> the most illogic part of ruby. Because of this stuff like
>
> if flags & 0x01
> # do some stuff if flag is set
> end
>
> will execute in any case. Perhaps I'm biased because I'm a crazy C hacker
> but I can not believe that others do not fall into this trap. I realy like
> the clearness of the ruby syntax but this "everything but nil and false is
> true" logic is totaly non obvious and annoying.
>
> Why can't there be a to_bool converter for all numerical Classes?
> This converter could be used in boolean expressions, 0.to_bool would
> return false and all other numbers would return true.
> Probably the best way is to extend the Object class where to_bool would
> return true. Subclasses may than overload to_bool with a more complex
> version. This makes it possible to use .to_bool everywhere where a boolean
> expression is expected.
>
> IMO if it looks like a boolean expression it should act like a boolean
> expression.
> -- 
> :wq Claudio
>
>