Last Updated: February 25, 2016
·
303
· ruianderson

How to check in an elegant way if an object is in a collection

Usually we use Collection#include? method on Rails when checking if a object is part of a collection.

You can do this in a different way and elegant:

life_characters = %w(Pinkman Walter)
"Hank".in? life_characters #=> false
"Walter".in? life_characters #=> true

The argument of in? method should respond to include?