Ruby 中的多重不等式 [英] Multiple Inequalities in Ruby

查看:47
本文介绍了Ruby 中的多重不等式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完整的红宝石菜鸟.

我有一个值,我想检查多个数字 (1,4,7),如果它等于其中任何一个,则返回 false.

现在我正在使用:

如果 $my_variable_class[1] != 1 &&$my_variable_class[1] != 4 &&$my_variable_class[1] != 7

我有一大堆数字来检查不平等.有没有更有效的方法来处理这个问题?

解决方案

也许 除非 [1,4,7].include?($my_variable[1]) 能解决问题?>

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?

这篇关于Ruby 中的多重不等式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆