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
[1,2,4].include? some_variable
a = [1,3,4]
a.indclude?(some_variable)
If you want to do something conditionally, you can also do:
case some_variable
when 1, 2, 4
blahblah
else
blahblah
end
精彩评论