What is true?
Posted by tom March 20th, 2006
This is one I needed to write down, in case I forget: In Ruby any value that is not nil or false is true.
puts “nil is true” if nil
puts “false is true” if false
puts “true is true” if true
c = ””
puts ”\”\” is true” if c
puts “0 is true” if 0
c = ””
if( c == ”” ) then
puts “yeah”
end
if( c ) then
puts “yep!”
end
will output:
true is true "" is true 0 is true yeah yep!

Leave a Reply