summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorBurdetteLamar <burdettelamar@yahoo.com>2025-08-21 17:36:09 -0500
committerPeter Zhu <peter@peterzhu.ca>2025-08-21 18:52:15 -0400
commit6fbe2dd36e30a2ecbfa770d3ebfbb8e601d97bd3 (patch)
tree6ed982064b108819658c7cc4d6d30ed60ce2c2ce /doc
parent823d55a8279aad5ad0eb2b83d45885443edfec83 (diff)
[DOC] Tweaks for String#insert
Diffstat (limited to 'doc')
-rw-r--r--doc/string/insert.rdoc16
1 files changed, 16 insertions, 0 deletions
diff --git a/doc/string/insert.rdoc b/doc/string/insert.rdoc
new file mode 100644
index 0000000000..d8252d5ec5
--- /dev/null
+++ b/doc/string/insert.rdoc
@@ -0,0 +1,16 @@
+Inserts the given +other_string+ into +self+; returns +self+.
+
+If the given +index+ is non-negative, inserts +other_string+ at offset +index+:
+
+ 'foo'.insert(0, 'bar') # => "barfoo"
+ 'foo'.insert(1, 'bar') # => "fbaroo"
+ 'foo'.insert(3, 'bar') # => "foobar"
+ 'тест'.insert(2, 'bar') # => "теbarст" # Characters, not bytes.
+ 'こんにちは'.insert(2, 'bar') # => "こんbarにちは"
+
+If the +index+ is negative, counts backward from the end of +self+
+and inserts +other_string+ _after_ the offset:
+
+ 'foo'.insert(-2, 'bar') # => "fobaro"
+
+Related: see {Modifying}[rdoc-ref:String@Modifying].