Method: Array#pop
- Defined in:
- array.c
permalink #pop ⇒ Object? #pop(n) ⇒ Object
Removes the last element from self
and returns it, or nil
if the array is empty.
If a number n is given, returns an array of the last n elements (or less) just like array.slice!(-n, n)
does.
a = [ "a", "b", "c", "d" ]
a.pop #=> "d"
a.pop(2) #=> ["b", "c"]
a #=> ["a"]
|
# File 'array.c'
static VALUE
rb_ary_pop_m(int argc, VALUE *argv, VALUE ary)
{
VALUE result;
if (argc == 0) {
return rb_ary_pop(ary);
}
|