false
and nil
evaluate to false in Ruby
. Anything else? Please provide links to official/authoritative references.
You just found them all
In Ruby, false and nil are “falsy”, while all other values are “truthy”
as Yehuda Katz mentioned in his blog post in 2009
false
and nil
are the only ones:
http://www.ruby-doc.org/core-2.1.1/FalseClass.html
Rails provides present?
which also includes empty strings and empty arrays: http://api.rubyonrails.org/classes/Object.html#method-i-present-3F
I can only agree, that nil
and false
are indeed the only two values, that evaluate to false in Ruby. I just wanted to point to another useful resource:
True and False vs. "Truthy" and "Falsey" (or "Falsy") in Ruby, Python, and JavaScript
The only false
-y values in Ruby are false
and nil
, as attested to by the book "The Ruby Programming Language", by David Flanagan and Yukihiro Matsumoto (the Matz):
Predicates typically return one of the Boolean values
true
orfalse
, but this is not required, as any value other thanfalse
ornil
works liketrue
when a Boolean value is required. (TheNumeric
methodnonzero?
, for example, returnsnil
if the number it is invoked on is zero, and just returns the number otherwise.)
(emphasis mine)
This quote can be found on page 180 of the book.