Possible Duplicate:
Elegant chained 'or's for tests on same variable in Ruby
I am using Ruby on Rails 3.2.2 and I would like to know if there are shorter ways to perform same checks as in the following:
if (variable == 'A') or (variable == 'B')
...
end
if (variable == 'A') or (variable == 'B') or ... or (variable == 'Z')
...
end
Note that I have to repeat statements related to the variable == “part” more than once and one time for each check. I would not repeat that “part” and make things shorter. Is it possible in Ruby/Ruby on Rails? If so, how can I make that?
Here’s one way:
or if you have an actual range of values: