39

Possible Duplicate:
how to check if my array includes an object - rails

I have array

array['one', 'two', 'three']

How i find that 'two' element present in array.

Is any method in ruby which can find this?

Thanks

0

3 Answers 3

80

array.include?('two') returns true or false

11

http://ruby-doc.org/core/classes/Array.html#M002203

array.include?('two')
6

you can use:

array.index('two')

will return index of object if present else will return nil.

Not the answer you're looking for? Browse other questions tagged or ask your own question.