End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
String#replace
replace(other_string) → self
string.c
View on GitHub ↗
VALUE
rb_str_replace(VALUE str, VALUE str2)
{
str_modifiable(str);
if (str == str2) return str;
StringValue(str2);
str_discard(str);
return str_replace(str, str2);
}
Alias of #initialize_copy
Replaces the contents of self with the contents of other_string:
Example
s = 'foo' # => "foo" s.replace('bar') # => "bar"