Ruby: True/False (boolean)
true
and false
are builtin objects.
The following evaluates to false:
false
nil
Everything else is true (including 0
, 0.0
, "0"
, ""
, []
). (this is similar to emacs lisp. [see Emacs Lisp Basics])
# -*- coding: utf-8 -*- # ruby if false then p "yes" else p "no" end # "no" if nil then p "yes" else p "no" end # "no" if () then p "yes" else p "no" end # "no" # Empty paren eval to nil, so false.
# -*- coding: utf-8 -*- # ruby if true then p "yes" else p "no" end # "yes" if 0 then p "yes" else p "no" end # "yes" if 0.0 then p "yes" else p "no" end # "yes" if [] then p "yes" else p "no" end # "yes" if {} then p "yes" else p "no" end # "yes" if "" then p "yes" else p "no" end # "yes"