Method: Array#push

Defined in:
array.c

#push(*objects) ⇒ self #append(*objects) ⇒ self Also known as: append

Appends each argument in objects to self; returns self:

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

Appends each argument as a single element, even if it is another array:

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

Related: see Methods for Assigning.

Overloads:

  • #push(*objects) ⇒ self

    Returns:

    • (self)
  • #append(*objects) ⇒ self

    Returns:

    • (self)


1418
1419
1420
1421
1422
# File 'array.c', line 1418

static VALUE
rb_ary_push_m(int argc, VALUE *argv, VALUE ary)
{
    return rb_ary_cat(ary, argv, argc);
}