Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Enumerable#drop_while

enum.drop_while { |obj| block } → array
enum.drop_while → an_enumerator

Drops elements up to, but not including, the first element for which the block returns nil or false and returns an array containing the remaining elements.

If no block is given, an enumerator is returned instead.

Example
a = [1, 2, 3, 4, 5, 0]
a.drop_while { |i| i < 3 }   #=> [3, 4, 5, 0]
See also #drop #each_cons #detect #each_entry also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1