Skip to content
instance method

Enumerable#drop_while

() { (Elem) -> ::boolish } -> ::Array[Elem]
() -> ::Enumerator[Elem, ::Array[Elem]]
drop_while {|element| ... } → array
drop_while → enumerator

Calls the block with successive elements as long as the block returns a truthy value; returns an array of all elements after that point:

Example
(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.

Example
e = (1..4).drop_while
p e #=> #<Enumerator: 1..4:drop_while>
i = e.next; p i; e.feed(i < 3) #=> 1
i = e.next; p i; e.feed(i < 3) #=> 2
i = e.next; p i; e.feed(i < 3) #=> 3
begin
  e.next
rescue StopIteration
  p $!.result #=> [3, 4]
end
See also #drop #each_cons #detect #each_entry also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0