开发者

Multiple Inequalities in Ruby

开发者 https://www.devze.com 2023-02-15 19:07 出处:网络
Complete ruby noob. I have a value which I want to check against several numbers (1,4,7) and if it equals any 开发者_如何学运维of them, return false.

Complete ruby noob.

I have a value which I want to check against several numbers (1,4,7) and if it equals any 开发者_如何学运维of them, return false.

right now I'm using:

if $my_variable_class[1] != 1 && $my_variable_class[1] != 4 && $my_variable_class[1] != 7  

I've got a shit-ton of numbers to check for inequality against. Is there a more efficient way to handle this?


Maybe unless [1,4,7].include?($my_variable[1]) will do the trick?


unless [1,4,7].include? $my_variable[1]
  do_smth
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号