array.include?(obj) → true or false
Returns true if the given object is present in self (that is, if any object == anObject), false otherwise.
a = [ "a", "b", "c" ] a.include?("b") #=> true a.include?("z") #=> false
Source Code
/* * call-seq: * array.include?(obj) -> true or false * * Returns <code>true</code> if the given object is present in * <i>self</i> (that is, if any object <code>==</code> <i>anObject</i>), * <code>false</code> otherwise. * * a = [ "a", "b", "c" ] * a.include?("b") #=> true * a.include?("z") #=> false */ VALUE rb_ary_includes(ary, item) VALUE ary; VALUE item; { long i; for (i=0; i<RARRAY(ary)->len; i++) { if (rb_equal(RARRAY(ary)->ptr[i], item)) { return Qtrue; } } return Qfalse; }
<code/>and<pre/>for code samples.