From 33776598f70dc0adfd7b0d62a0a0df2e2c36b172 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Thu, 8 Oct 2020 15:35:13 -0500 Subject: Enhanced RDoc for String#insert (#3643) * Enhanced RDoc for String#insert --- string.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index d57d949c09..556b03addc 100644 --- a/string.c +++ b/string.c @@ -4611,6 +4611,8 @@ rb_str_aref(VALUE str, VALUE indx) * string[regexp, capture = 0] -> new_string or nil * string[substring] -> new_string or nil * + * Returns the substring of +self+ specified by the arguments. + * * When the single \Integer argument +index+ is given, * returns the 1-character substring found in +self+ at offset +index+: * 'bar'[2] # => "r" @@ -4915,19 +4917,17 @@ rb_str_aset_m(int argc, VALUE *argv, VALUE str) /* * call-seq: - * str.insert(index, other_str) -> str - * - * Inserts other_str before the character at the given - * index, modifying str. Negative indices count from the - * end of the string, and insert after the given character. - * The intent is insert aString so that it starts at the given - * index. - * - * "abcd".insert(0, 'X') #=> "Xabcd" - * "abcd".insert(3, 'X') #=> "abcXd" - * "abcd".insert(4, 'X') #=> "abcdX" - * "abcd".insert(-3, 'X') #=> "abXcd" - * "abcd".insert(-1, 'X') #=> "abcdX" + * string.insert(index, other_string) -> self + * + * Inserts the given +other_string+ into +self+; returns +self+. + * + * If the \Integer +index+ is positive, inserts +other_string+ at offset +index+: + * 'foo'.insert(1, 'bar') # => "fbaroo" + * + * If the \Integer +index+ is negative, counts backward from the end of +self+ + * and inserts +other_string+ at offset index+1 + * (that is, _after_ self[index]): + * 'foo'.insert(-2, 'bar') # => "fobaro" */ static VALUE -- cgit v1.2.1