I'm new to Ruby and I was surprised when I found out that all objects are true apart from nil and false. Even 0 is true.
A nice thing about that property of the language is that you can write:
if !variable
# do stuff when variable is nil
end
My colleagues, who are more seasoned Ruby developers, insist I should choose that instead of using .nil? like so:
if variable.nil?
# do stuff when variable is nil
end
However I believe that the latter is a better option for two reasons: 1. I think it's more object oriented, especially in a language like Ruby where everything is an object and message exchange. 2. It is more readable, in my subject opinion, even if it is less compact.
Am I making a "newbie" mistake here?