Skip to content
instance method

Array#*

(::string str) -> ::String
(::int int) -> ::Array[Elem]
self * n → new_array
self * string_separator → new_string

When non-negative integer argument n is given, returns a new array built by concatenating 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 self.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 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0