tags:

views:

134

answers:

3

Hello,

If I have a value 'Dog' and an array ['Cat', 'Dog', 'Bird'] How do I check this w/o looping through. Is there a simple way of checking if the value exists, nothing more.

+5  A: 

You're looking for include?:

>> ['Cat', 'Dog', 'Bird'].include? 'Dog'
=> true
Brian Campbell
+1  A: 

a.include? 'Dog'

DigitalRoss
+5  A: 

Try

['Cat', 'Dog', 'Bird'].include?('Dog')
schmitzelburger