Ruby 1.9.3 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Stringクラス > insert

instance method String#insert

insert(pos, other) -> ()

pos 番目の文字の直前に文字列 other を挿入します。 self[pos, 0] = other と同じ操作です。

[PARAM] pos:
文字列を挿入するインデックス
[PARAM] other:
挿入する文字列

例:

str = "foobaz"
str.insert(3, "bar")
p str   # => "foobarbaz"

[SEE_ALSO] String#[]=

class String