method
initialize_copy
v1_9_1_378 -
Show latest stable
- Class:
String
initialize_copy(p1)public
Replaces the contents and taintedness of str with the corresponding values in other_str.
s = "hello" #=> "hello" s.replace "world" #=> "world"
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;
} Related methods
- Instance methods
- %
- *
- +
- <<
- <=>
- ==
- ===
- =~
- []
- []=
- ascii_only?
- block_scanf
- bytes
- bytesize
- capitalize
- capitalize!
- casecmp
- center
- chars
- chomp
- chomp!
- chop
- chop!
- chr
- clear
- codepoints
- concat
- count
- crypt
- delete
- delete!
- downcase
- downcase!
- dump
- each_byte
- each_char
- each_codepoint
- each_line
- empty?
- encode
- encode!
- encoding
- end_with?
- eql?
- force_encoding
- getbyte
- gsub
- gsub!
- hash
- hex
- include?
- index
- initialize_copy
- insert
- inspect
- intern
- is_binary_data?
- is_complex_yaml?
- iseuc
- isjis
- issjis
- isutf8
- kconv
- length
- lines
- ljust
- lstrip
- lstrip!
- match
- next
- next!
- oct
- ord
- parse_csv
- partition
- replace
- reverse
- reverse!
- rindex
- rjust
- rpartition
- rstrip
- rstrip!
- scan
- scanf
- setbyte
- shellescape
- shellsplit
- size
- slice
- slice!
- split
- squeeze
- squeeze!
- start_with?
- strip
- strip!
- sub
- sub!
- succ
- succ!
- sum
- swapcase
- swapcase!
- to_c
- to_d
- to_f
- to_i
- to_r
- to_s
- to_str
- to_sym
- to_yaml
- toeuc
- tojis
- tolocale
- tosjis
- toutf16
- toutf32
- toutf8
- tr
- tr!
- tr_s
- tr_s!
- unpack
- upcase
- upcase!
- upto
- valid_encoding?
- Class methods
- new
- try_convert
- yaml_new