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#prepend

prepend(*args)

Alias of #unshift

Prepends the given objects to self:

Example
a = [:foo, 'bar', 2]
a.unshift(:bam, :bat) # => [:bam, :bat, :foo, "bar", 2]

Array#prepend is an alias for Array#unshift.

Related: push, pop, shift.

See also #unshift #pop #product #permutation also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1