Is it normal for methods with a question mark to return something that\'s truthy (for example, a number) to indicate that something is true, or should true
itself b
It is usual for methods ending with ?
to return either true
or false
but it is not systematic and no core method will assume it.
An example in the core classes is Numeric#nonzero?
which never returns true
or false
.
42.nonzero? # => 42
The library Set
has add?
and delete?
too. I wish Enumerable#one?
returned nil
or false
to distinguish cases where the count is zero from when it is greater than one.
A similar example are the comparison operators (<
, >
, ...), which usually return only true
or false
. Here again exceptions exist for Module
's operators that will return nil
instead when the two modules are not related:
Array > Enumerable # => false
Array > Fixnum # => nil