views:

35

answers:

2

Is the following statement possible with Rails/Ruby? If so, how :)

IF XXX Equals At Least One (Var1, Var2, Var3)

+1  A: 
if [a, b, c].find_index(XXX)

Sounds simple enough. And there's nothing wrong with classical way too:

if XXX == a || XXX == b || XXX == c
Nikita Rybak
+5  A: 

Try this:

if [v1, v2, v3].any?{|v| v=="XXX"}
 p "Success"
end

OR

if [v1, v2, v3].include?("XXX")
 p "Success"
end
KandadaBoggu
both of these were great fast answers. thank you
AnApprentice