Skip to content
instance method

Array#drop

(::int n) -> ::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.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0