檢查Ruby中的數組中是否存在值 - Check if a value exists in an array in Ruby

問題:

I have a value 'Dog' and an array ['Cat', 'Dog', 'Bird'] . 我有一個值'Dog'和一個陣列['Cat', 'Dog', 'Bird'] 數組

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? 是否有一種簡單的方法來檢查值是否存在,僅此而已? oop


解決方案:

參考一: https://stackoom.com/question/8KkU/檢查Ruby中的數組中是否存在值
參考二: https://oldbug.net/q/8KkU/Check-if-a-value-exists-in-an-array-in-Ruby