Skip to content

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

instance method

Array#<<

array << object → self

Appends object to self; returns self:

Example
a = [:foo, 'bar', 2]
a << :baz # => [:foo, "bar", 2, :baz]

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

Example
a = [:foo, 'bar', 2]
a1 = a << [3, 4]
a1 # => [:foo, "bar", 2, [3, 4]]
See also #- #<=> #+ #== also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0