File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1846,16 +1846,24 @@ offset が負の場合、文字列の末尾から数えた位置から探索し
18461846#@end
18471847--- insert(pos, other) -> self
18481848
1849- pos 番目の文字の直前に文字列 other を挿入します。
1849+ 文字列 other を self に挿入して self を返します。
1850+
1851+ pos が正の場合、pos 番目の文字の直前に文字列 other を挿入します。
18501852self[pos, 0] = other と同じ操作です。
18511853
1854+ pos が負の場合、self の末尾から逆方向に数えて pos+1 (self[index] の後) に other を挿入します。
1855+
18521856@param pos 文字列を挿入するインデックス
18531857@param other 挿入する文字列
18541858
18551859#@samplecode 例
1856- str = "foobaz"
1857- str.insert(3, "bar")
1858- p str # => "foobarbaz"
1860+ # pos が正の場合、String#insert と String#[]= は同じ操作を行う
1861+ 'foo'.insert(1, 'bar') # => "fbaroo"
1862+ str = 'foo'; str[1, 0] = 'bar'; str # => "fbaroo"
1863+
1864+ # pos が負の場合、String#insert と String#[]= は異なる操作を行う
1865+ 'foo'.insert(-1, 'bar') # => "foobar"
1866+ str = 'foo'; str[-1, 0] = 'bar'; str # => "fobaro"
18591867#@end
18601868
18611869@see [[m:String#[]=]]
You can’t perform that action at this time.
0 commit comments