Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Array#*

array * n → new_array
array * string_separator → new_string

When non-negative argument Integer n is given, returns a new Array built by concatenating the n copies of self:

Example
a = ['x', 'y']
a * 3 # => ["x", "y", "x", "y", "x", "y"]

When String argument string_separator is given, equivalent to array.join(string_separator):

Example
[0, [0, 1], {foo: 0}] * ', ' # => "0, 0, 1, {:foo=>0}"

Ruby version changes

  1. 3.0
See also #& #+ .try_convert #- also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1