By convention, functions that return
false have a name which ends with a question mark. The grammar of those function names is odd, though. Compare the following:
When read out loud, the full sentence sounds different for each:
Array#empty?— array is empty
Hash#key?(k)— hash has key
The (unofficial) Ruby style guide suggests
s), but Rails only provides
exists? as method names.
An alternative to
has_key?, which the (unofficial) Ruby style guide discourages. For consistency with the
#exist?, it’d have to be
have_key? which is not used anywhere, as far as I can tell, probably because it sounds weird.
For grammatical consistency, the methods would better be named as follows:
But in these new forms, there’s not much of a reason left to include a trailing
? . The meaning of these functions is clear without it. Consider:
Array#empty— used for emptying an array
Array#is_empty— used for checking whether an array is empty
Car#key— used for keying a car (what kind of example is this, Denis?!)
Car#keyed— used for returning a keyed copy of a car
Car#is_keyed— used for checking if the car is keyed.
(I don’t own a car, by the way.)