replace(p1)
public
Replaces the contents and taintedness of str with the
corresponding values in other_str.
s = "hello"
s.replace "world"
Show source
VALUE
rb_str_replace(VALUE str, VALUE str2)
{
long len;
if (str == str2) return str;
StringValue(str2);
len = RSTRING_LEN(str2);
if (STR_ASSOC_P(str2)) {
str2 = rb_str_new4(str2);
}
if (str_independent(str) && !STR_EMBED_P(str)) {
xfree(RSTRING_PTR(str));
}
if (STR_SHARED_P(str2)) {
STR_SET_NOEMBED(str);
RSTRING(str)->as.heap.len = len;
RSTRING(str)->as.heap.ptr = RSTRING_PTR(str2);
FL_SET(str, ELTS_SHARED);
FL_UNSET(str, STR_ASSOC);
RSTRING(str)->as.heap.aux.shared = RSTRING(str2)->as.heap.aux.shared;
}
else {
str_replace_shared(str, rb_str_new4(str2));
}
OBJ_INFECT(str, str2);
rb_enc_cr_str_exact_copy(str, str2);
return str;
}