Skip to content

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

instance method

Enumerable#drop

drop(n) → array

For positive integer n, returns an array containing all but the first n elements:

Example
r = (1..4)
r.drop(3)  # => [4]
r.drop(2)  # => [3, 4]
r.drop(1)  # => [2, 3, 4]
r.drop(0)  # => [1, 2, 3, 4]
r.drop(50) # => []

h = {foo: 0, bar: 1, baz: 2, bat: 3}
h.drop(2) # => [[:baz, 2], [:bat, 3]]
See also #detect #drop_while #cycle #each_cons also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0