Is there a method in the Ruby array object that gives anything like a
“contains?” method, to test if an object is already in the Array?
For the time being, I’ve extended the Array class as follows:
http://pastie.org/1627594
I wondered if this was a good way, or if there was already something in
the API that allowed for this. I couldn’t seem to find anything…
azgar
2
On Wed, Mar 2, 2011 at 10:12 PM, Paul S. [email protected]
wrote:
Array.include?
azgar
3
2011/3/3 Paul S. [email protected]:
Is there a method in the Ruby array object that gives anything like a
“contains?” method, to test if an object is already in the Array?
How about include?
azgar
4
Returns the index of the first object in self such that is == to
obj.
Returns nil if no match is found.
a = [ “a”, “b”, “c” ]
a.index(“b”) #=> 1
a.index(“z”) #=> nil
M. Karuppasamy
azgar
5
“屋国遥” [email protected] wrote in post #985112:
2011/3/3 Paul S. [email protected]:
Is there a method in the Ruby array object that gives anything like a
“contains?” method, to test if an object is already in the Array?
How about include?
Yes, that’s want I wanted… 
thanks…