Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Array#initialize_copy

(self other_ary) -> void
initialize_copy(other_array) → self

Replaces the elements of self with the elements of other_array, which must be an array-convertible object; returns self:

Example
a = ['a', 'b', 'c']   # => ["a", "b", "c"]
a.replace(['d', 'e']) # => ["d", "e"]

Related: see Methods for Assigning.

See also #index #insert #include? #inspect also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0