summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurdette Lamar <[email protected]>2024-09-29 20:21:11 -0500
committerGitHub <[email protected]>2024-09-29 21:21:11 -0400
commit154ec2d242c9f3063d810598d401ed297e4777fd (patch)
treefc6ad90f91069d5a95bcbe65cdbe2153462cf92d
parent9b4a497456b3f538c4d3237f941f634f97e0e30e (diff)
[DOC] Tweaks for Array#insert (#11709)
-rw-r--r--array.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/array.c b/array.c
index 52b0fe6b99..11d68361b0 100644
--- a/array.c
+++ b/array.c
@@ -2522,38 +2522,38 @@ rb_ary_aset(int argc, VALUE *argv, VALUE ary)
/*
* call-seq:
- * array.insert(index, *objects) -> self
+ * insert(index, *objects) -> self
*
- * Inserts given +objects+ before or after the element at Integer index +offset+;
+ * Inserts the given +objects+ as elements of +self+;
* returns +self+.
*
- * When +index+ is non-negative, inserts all given +objects+
- * before the element at offset +index+:
+ * When +index+ is non-negative, inserts +objects+
+ * _before_ the element at offset +index+:
*
- * a = [:foo, 'bar', 2]
- * a.insert(1, :bat, :bam) # => [:foo, :bat, :bam, "bar", 2]
+ * a = ['a', 'b', 'c'] # => ["a", "b", "c"]
+ * a.insert(1, :x, :y, :z) # => ["a", :x, :y, :z, "b", "c"]
*
* Extends the array if +index+ is beyond the array (<tt>index >= self.size</tt>):
*
- * a = [:foo, 'bar', 2]
- * a.insert(5, :bat, :bam)
- * a # => [:foo, "bar", 2, nil, nil, :bat, :bam]
+ * a = ['a', 'b', 'c'] # => ["a", "b", "c"]
+ * a.insert(5, :x, :y, :z) # => ["a", "b", "c", nil, nil, :x, :y, :z]
*
- * Does nothing if no objects given:
+ * When +index+ is negative, inserts +objects+
+ * _after_ the element at offset <tt>index + self.size</tt>:
*
- * a = [:foo, 'bar', 2]
- * a.insert(1)
- * a.insert(50)
- * a.insert(-50)
- * a # => [:foo, "bar", 2]
+ * a = ['a', 'b', 'c'] # => ["a", "b", "c"]
+ * a.insert(-2, :x, :y, :z) # => ["a", "b", :x, :y, :z, "c"]
*
- * When +index+ is negative, inserts all given +objects+
- * _after_ the element at offset <tt>index+self.size</tt>:
+ * With no +objects+ given, does nothing:
*
- * a = [:foo, 'bar', 2]
- * a.insert(-2, :bat, :bam)
- * a # => [:foo, "bar", :bat, :bam, 2]
+ * a = ['a', 'b', 'c'] # => ["a", "b", "c"]
+ * a.insert(1) # => ["a", "b", "c"]
+ * a.insert(50) # => ["a", "b", "c"]
+ * a.insert(-50) # => ["a", "b", "c"]
+ *
+ * Raises IndexError if +objects+ are given and +index+ is negative and out of range.
*
+ * Related: see {Methods for Assigning}[rdoc-ref:Array@Methods+for+Assigning].
*/
static VALUE