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

(::int count) -> ::Array[Elem]
drop(count) → new_array

Returns a new array containing all but the first count element of self, where count is a non-negative integer; does not modify self.

Examples:

Example
a = [0, 1, 2, 3, 4, 5]
a.drop(0) # => [0, 1, 2, 3, 4, 5]
a.drop(1) # => [1, 2, 3, 4, 5]
a.drop(2) # => [2, 3, 4, 5]
a.drop(9) # => []

Related: see Methods for Fetching.

Ruby version changes

  1. 3.0
See also #dig #drop_while #difference #each also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0