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

append(*args)

Alias of #push

Appends trailing elements.

Appends each argument in objects to self; returns self:

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

Appends each argument as one element, even if it is another Array:

Example
a = [:foo, 'bar', 2]
a1 = a.push([:baz, :bat], [:bam, :bad])
a1 # => [:foo, "bar", 2, [:baz, :bat], [:bam, :bad]]

Array#append is an alias for Array#push.

Related: pop, shift, unshift.

See also #push #any? #assoc #all? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1