Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

String#initialize_copy

(::string other_string) -> self
initialize_copy(p1)

Alias of #replace

Replaces the contents of self with the contents of other_string; returns self:

Example
s = 'foo'        # => "foo"
s.replace('bar') # => "bar"

Related: see Modifying.

See also #replace #index #insert #include? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0