检查是否在Ruby中数组存在价值 [英] Check if a value exists in an array in Ruby
本文介绍了检查是否在Ruby中数组存在价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个值狗
和阵列 ['猫','狗','鸟']
。
我如何检查它是否存在于数组中,而无需通过它循环?是否有检查的一个简单的方法,如果存在的价值,仅此而已?
How do I check if it exists in the array without looping through it? Is there a simple way of checking if the value exists, nothing more?
推荐答案
您正在寻找的 包含
:
You're looking for include?
:
>> ['Cat', 'Dog', 'Bird'].include? 'Dog'
=> true
这篇关于检查是否在Ruby中数组存在价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文