I am new to Ruby and came across the defined? operator. I thought the ? implied that the method returned true/false but defined? returns a description of the identifier if it is defined.
I know that there is a true/false component in that the identifier is or is not defined but I thought that the ? meant that the return value always had to be true/false`. Help?
It returns a “truthy” value that is either “truthy-true” or “truthy-false”.
In Ruby, there are only two things that are truthy-false:
false(the singleton object)nil(the singleton object)Anything else is considered truthy-true. Tons of Ruby code leverages this fact for predicates. Checks for predicates, as such, should be:
not: