Easily compare a variable with multiple values
I often forget this simple little trick for comparing multiple values against a single variable.
Instead of
var = 2
if var == 1 || var == 2 || var == 3
puts "yes"
end
#=> "yes"
if var == 1 || var == 2 || var == 3
puts "yes"
end
#=> "yes"
You can do the following
var = 2
if [1,2,3].include?(var)
puts "yes"
end
#=> "yes"
if [1,2,3].include?(var)
puts "yes"
end
#=> "yes"


Thanks for the reminder, I’d forgotten this technique.
PS. are you the Andrew Timberlake that sold me a Cape Epic entry a few years back?
That would be me