summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurdette Lamar <[email protected]>2024-10-12 09:36:29 -0500
committerGitHub <[email protected]>2024-10-12 10:36:29 -0400
commit81910a93ff2688fc1a6d4a5200782869105e8872 (patch)
treebff0fd3aac59932fce9add353c1c8ad03409d740
parentafacb8ada5788299468cce6247601412e12002a4 (diff)
[DOC] Tweaks for Array#shift (#11886)
Notes
Notes: Merged-By: peterzhu2118 <[email protected]>
-rw-r--r--array.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/array.c b/array.c
index b6768e52d3..015395f74c 100644
--- a/array.c
+++ b/array.c
@@ -1512,35 +1512,40 @@ rb_ary_shift(VALUE ary)
/*
* call-seq:
- * array.shift -> object or nil
- * array.shift(n) -> new_array
+ * shift -> object or nil
+ * shift(count) -> new_array or nil
*
- * Removes and returns leading elements.
+ * Removes and returns leading elements from +self+.
*
- * When no argument is given, removes and returns the first element:
+ * With no argument, removes and returns one element, if available,
+ * or +nil+ otherwise:
*
- * a = [:foo, 'bar', 2]
- * a.shift # => :foo
- * a # => ['bar', 2]
- *
- * Returns +nil+ if +self+ is empty.
+ * a = [0, 1, 2, 3]
+ * a.shift # => 0
+ * a # => [1, 2, 3]
+ * [].shift # => nil
*
- * When positive Integer argument +n+ is given, removes the first +n+ elements;
- * returns those elements in a new +Array+:
+ * With non-negative numeric argument +count+ given,
+ * removes and returns the first +count+ elements:
*
- * a = [:foo, 'bar', 2]
- * a.shift(2) # => [:foo, 'bar']
- * a # => [2]
+ * a = [0, 1, 2, 3]
+ * a.shift(2) # => [0, 1]
+ * a # => [2, 3]
+ * a.shift(1.1) # => [2]
+ * a # => [3]
+ * a.shift(0) # => []
+ * a # => [3]
*
- * If +n+ is as large as or larger than <tt>self.length</tt>,
- * removes all elements; returns those elements in a new +Array+:
+ * If +count+ is large,
+ * removes and returns all elements:
*
- * a = [:foo, 'bar', 2]
- * a.shift(3) # => [:foo, 'bar', 2]
+ * a = [0, 1, 2, 3]
+ * a.shift(50) # => [0, 1, 2, 3]
+ * a # => []
*
- * If +n+ is zero, returns a new empty +Array+; +self+ is unmodified.
+ * If +self+ is empty, returns a new empty array.
*
- * Related: #push, #pop, #unshift.
+ * Related: see {Methods for Deleting}[rdoc-ref:Array@Methods+for+Deleting].
*/
static VALUE