0

Possible Duplicate:
Multiple Inequalities in Ruby

Hi All, I have an ugly logical expression, and I just know there's a much nicer, more concise way to phrase this in ruby:

some_variable == 1 || some_variable == 2 || some_variable == 4

All suggestions welcomed, Thanks

Community
  • 1
  • 1
Paul Nelligan
  • 2,015
  • 2
  • 18
  • 18

3 Answers3

5
[1,2,4].include? some_variable
Jakub Hampl
  • 39,863
  • 10
  • 77
  • 106
0
a = [1,3,4]
a.indclude?(some_variable)
Alex Polkhovsky
  • 3,340
  • 5
  • 29
  • 37
0

If you want to do something conditionally, you can also do:

case some_variable
when 1, 2, 4
    blahblah
else
    blahblah
end
sawa
  • 165,429
  • 45
  • 277
  • 381