Skip to content

Commit

Permalink
[DOC] Tweaks for Array#insert (ruby#11709)
Browse files Browse the repository at this point in the history
  • Loading branch information
BurdetteLamar committed Sep 30, 2024
1 parent 9b4a497 commit 154ec2d
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 154ec2d

Please sign in to comment.