reject!()
public
Equivalent to Array#delete_if, deleting elements from self for
which the block evaluates to true, but returns nil if no changes were made.
Also see Enumerable#reject.
Show source
/*
* call-seq:
* array.reject! {|item| block } -> array or nil
*
* Equivalent to <code>Array#delete_if</code>, deleting elements from
* _self_ for which the block evaluates to true, but returns
* <code>nil</code> if no changes were made. Also see
* <code>Enumerable#reject</code>.
*/
static VALUE
rb_ary_reject_bang(ary)
VALUE ary;
{
long i1, i2;
RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
VALUE v = RARRAY(ary)->ptr[i1];
if (RTEST(rb_yield(v))) continue;
if (i1 != i2) {
rb_ary_store(ary, i2, v);
}
i2++;
}
if (RARRAY(ary)->len == i2) return Qnil;
if (i2 < RARRAY(ary)->len)
RARRAY(ary)->len = i2;
return ary;
}