Skip to content

Commit deba4d3

Browse files
Tweaks for String#replace
1 parent fb3b895 commit deba4d3

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

doc/string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@
398398
# - #gsub!: Replaces each substring that matches a given pattern with a given replacement string;
399399
# returns +self+ if any changes, +nil+ otherwise.
400400
# - #succ! (aliased as #next!): Returns +self+ modified to become its own successor.
401-
# - #initialize_copy (aliased as #replace): Returns +self+ with its entire content replaced by a given string.
401+
# - #replace: Returns +self+ with its entire content replaced by a given string.
402402
# - #reverse!: Returns +self+ with its characters in reverse order.
403403
# - #setbyte: Sets the byte at a given integer offset to a given value; returns the argument.
404404
# - #tr!: Replaces specified characters in +self+ with specified replacement characters;

string.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6648,11 +6648,13 @@ rb_str_gsub(int argc, VALUE *argv, VALUE str)
66486648
* call-seq:
66496649
* replace(other_string) -> self
66506650
*
6651-
* Replaces the contents of +self+ with the contents of +other_string+:
6651+
* Replaces the contents of +self+ with the contents of +other_string+;
6652+
* returns +self+:
66526653
*
66536654
* s = 'foo' # => "foo"
66546655
* s.replace('bar') # => "bar"
66556656
*
6657+
* Related: see {Modifying}[rdoc-ref:String@Modifying].
66566658
*/
66576659

66586660
VALUE
@@ -12820,6 +12822,7 @@ Init_String(void)
1282012822
rb_define_singleton_method(rb_cString, "new", rb_str_s_new, -1);
1282112823
rb_define_singleton_method(rb_cString, "try_convert", rb_str_s_try_convert, 1);
1282212824
rb_define_method(rb_cString, "initialize", rb_str_init, -1);
12825+
rb_define_method(rb_cString, "replace", rb_str_replace, 1);
1282312826
rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);
1282412827
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
1282512828
rb_define_method(rb_cString, "==", rb_str_equal, 1);
@@ -12850,7 +12853,6 @@ Init_String(void)
1285012853
rb_define_method(rb_cString, "byteindex", rb_str_byteindex_m, -1);
1285112854
rb_define_method(rb_cString, "rindex", rb_str_rindex_m, -1);
1285212855
rb_define_method(rb_cString, "byterindex", rb_str_byterindex_m, -1);
12853-
rb_define_method(rb_cString, "replace", rb_str_replace, 1);
1285412856
rb_define_method(rb_cString, "clear", rb_str_clear, 0);
1285512857
rb_define_method(rb_cString, "chr", rb_str_chr, 0);
1285612858
rb_define_method(rb_cString, "getbyte", rb_str_getbyte, 1);

0 commit comments

Comments
 (0)