Method: Enumerable#drop_while
- Defined in:
- enum.c
#drop_while {|element| ... } ⇒ Array #drop_while ⇒ Object
Calls the block with successive elements as long as the block returns a truthy value; returns an array of all elements after that point:
(1..4).drop_while{|i| i < 3 } # => [3, 4]
h = {foo: 0, bar: 1, baz: 2}
a = h.drop_while{|element| key, value = *element; value < 2 }
a # => [[:baz, 2]]
With no block given, returns an Enumerator.
3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 |
# File 'enum.c', line 3708
static VALUE
enum_drop_while(VALUE obj)
{
VALUE result;
struct MEMO *memo;
RETURN_ENUMERATOR(obj, 0, 0);
result = rb_ary_new();
memo = MEMO_NEW(result, 0, FALSE);
rb_block_call(obj, id_each, 0, 0, drop_while_i, (VALUE)memo);
return result;
}
|