I want to write code that others easily can understand as well.
Do boolean attributes like hide_email
or email_hidden
have a convention style?
I think of it like this:
is
. e.g. is <attribute_name>
or <attribute_name> is <something>
is
because Ruby prefers the ?
suffix for "is"-style method names (see below for more), leaving you with just <attribute_name>
or <attribute_name> <something>
.So, for your specific case, name your attribute like this:
is_email_hidden
or email_is_hidden
.is
and, either way, you're left with email_hidden
Why?
?
) corresponding to all boolean attributes and returns true
or false
. So, while your attribute is named email_hidden
in the database (somewhat stark feeling, no doubt) you can and should reference it as email_hidden?
in your code. Both for clarity and because this is the idiomatic Ruby on Rails way.