Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Array#drop_while

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

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:

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

Ruby version changes

  1. 3.0
See also #drop #each #dig #each_index also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0