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
enum.c
View on GitHub ↗
static VALUE
enum_drop(VALUE obj, VALUE n)
{
VALUE result;
struct MEMO *memo;
long len = NUM2LONG(n);
if (len < 0) {
rb_raise(rb_eArgError, "attempt to drop negative size");
}
result = rb_ary_new();
memo = MEMO_NEW(result, 0, len);
rb_block_call(obj, id_each, 0, 0, drop_i, (VALUE)memo);
return result;
}
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]]