Dec
7th
Fri
7th
I simply love the Ruby language, but one BIG annoyance is Ruby’s representation of false. Namely, nil and false are false, everything else is true. Where this causes problems is statements like:
if 4 & 1
puts “The number 4 has the 1 bit set”
else
puts “The number 4 does not have the 1 bit set”
end
In most every language I know, this will print “The number 4 does not have the 1 bit set.” Ruby, on the other hand, evaluates 4 & 1 to be 0, and the number ZERO in Ruby is true.
To make the above statement correct, you must say
if 4 & 1 != 0