Skip to content

[DOC] Tweaks for Array#pop #11821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1448,33 +1448,32 @@ rb_ary_pop(VALUE ary)

/*
* call-seq:
* array.pop -> object or nil
* array.pop(n) -> new_array
* pop -> object or nil
* pop(count) -> new_array
*
* Removes and returns trailing elements.
* Removes and returns trailing elements of +self+.
*
* When no argument is given and +self+ is not empty,
* removes and returns the last element:
* With no argument given, removes and returns the last element, if available;
* otherwise returns +nil+:
*
* a = [:foo, 'bar', 2]
* a.pop # => 2
* a # => [:foo, "bar"]
*
* Returns +nil+ if the array is empty.
* a.pop # => 2
* a # => [:foo, "bar"]
* [].pop # => nil
*
* When a non-negative Integer argument +n+ is given and is in range,
* With non-negative integer argument +count+ given,
* returns a new array containing the trailing +count+ elements of +self+, as available:
*
* removes and returns the last +n+ elements in a new +Array+:
* a = [:foo, 'bar', 2]
* a.pop(2) # => ["bar", 2]
*
* If +n+ is positive and out of range,
* removes and returns all elements:
* a # => [:foo]
*
* a = [:foo, 'bar', 2]
* a.pop(50) # => [:foo, "bar", 2]
* a # => []
*
* Related: #push, #shift, #unshift.
* Related: Array#push;
* see also {Methods for Deleting}[rdoc-ref:Array@Methods+for+Deleting].
*/

static VALUE
Expand Down