I often find
collection.include?(object) to read backwards. Consider
reads a lot better.
This may seem obvious to many. My intention is to promote the idea of doing things this way to those who hadn’t considered it, and the (rather straightforward) implementation as a convenience.
This is the code I use in a current Rails project:
1 2 3 4 5 6
The conditionals make it so you can do either
dog.in?([:pug, :bulldog]) (easier if the collection is in a variable/constant) or
dog.in?(:pug, :bulldog) (easier if you enumerate the collection right there). If you just want the former syntax,
1 2 3 4 5
For better readability still, try something like