End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
String#initialize_copy
str.replace(other_str) -> str
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);
}
Replaces the contents of str with the corresponding values in other_str.
Example
s = "hello" #=> "hello" s.replace "world" #=> "world"