This seems a ridiculously simple question to be asking, but what's the shortest/most idiomatic way of rewriting this in Ruby?
if variable == :a or variable == :b or variable == :c or variable == :d # etc.
I've previously seen this solution:
if [:a, :b, :c, :d].include? variable
but this isn't always functionally equivalent - I believe Array#include? actually looks to see if the variable object is contained in the list; it doesn't take into account that the object may implement its own equality test with def ==(other).
[EDIT: As observed by helpful commentators below, that explanation isn't correct. #include? does use == but it uses the == method of the items in the array - in my example, the symbols - rather than the == method of variable. That explains why it's not equivalent to my first code example.]
(Take, for example, Rails' Mime::Type implementation: request.format == :html may return true, but [:html].include?(request.format) will return false, as request.format is an instance of Mime::Type, not a symbol.)
The best I have so far is:
if [:a, :b, :c, :d].select {|f| variable == f}.any?
but it seems somewhat cumbersome to me. Any better suggestions?