APIdock / Ruby
/
method

drop

ruby latest stable - Class: Array
drop(p1)
public

Drops first n elements from ary and returns the rest of the elements in an array.

If a negative number is given, raises an ArgumentError.

See also Array#take

a = [1, 2, 3, 4, 5, 0]
a.drop (3) #=> [4, 5, 0]
static VALUE
rb_ary_drop(VALUE ary, VALUE n)
{
 VALUE result;
 long pos = NUM2LONG(n);
 if (pos < 0) {
 rb_raise(rb_eArgError, "attempt to drop negative size");
 }
 result = rb_ary_subseq(ary, pos, RARRAY_LEN(ary));
 if (result == Qnil) result = rb_ary_new();
 return result;
}

AltStyle によって変換されたページ (->オリジナル) /