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

array.unshift(*objects) → self

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 #uniq! #values_at #uniq #zip also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1