Method: Array#drop_while

Defined in:
array.c

#drop_while {|element| ... } ⇒ Object #drop_whileObject

With a block given, calls the block with each successive element of self; stops if the block returns false or nil; returns a new array omitting those elements for which the block returned a truthy value; does not modify self:

a = [0, 1, 2, 3, 4, 5]
a.drop_while {|element| element < 3 } # => [3, 4, 5]

With no block given, returns a new Enumerator.

Related: see Methods for Fetching.

Overloads:

  • #drop_while {|element| ... } ⇒ Object

    Yields:

    • (element)


7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
# File 'array.c', line 7732

static VALUE
rb_ary_drop_while(VALUE ary)
{
    long i;

    RETURN_ENUMERATOR(ary, 0, 0);
    for (i = 0; i < RARRAY_LEN(ary); i++) {
        if (!RTEST(rb_yield(RARRAY_AREF(ary, i)))) break;
    }
    return rb_ary_drop(ary, LONG2FIX(i));
}