rindex(p1)
public
Returns the index of the last object in array == to
obj. Returns nil if no match is found.
a = [ "a", "b", "b", "b", "c" ]
a.rindex("b")
a.rindex("z")
Show source
/*
* call-seq:
* array.rindex(obj) -> int or nil
*
* Returns the index of the last object in <i>array</i>
* <code>==</code> to <i>obj</i>. Returns <code>nil</code> if
* no match is found.
*
* a = [ "a", "b", "b", "b", "c" ]
* a.rindex("b") #=> 3
* a.rindex("z") #=> nil
*/
static VALUE
rb_ary_rindex(ary, val)
VALUE ary;
VALUE val;
{
long i = RARRAY(ary)->len;
while (i--) {
if (i > RARRAY(ary)->len) {
i = RARRAY(ary)->len;
continue;
}
if (rb_equal(RARRAY(ary)->ptr[i], val))
return LONG2NUM(i);
}
return Qnil;
}