Ruby’s question-mark boolean methods are inconsistent

By convention, functions that return true or 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:

The (unofficial) Ruby style guide suggests exist? over exists? (extra s), but Rails only provides exists? as method names.

An alternative to key? is 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:

(I don’t own a car, by the way.)


Note last edited March 2022.
Backlinks: What would I change about Ruby?.