Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Appends object to self; returns self:
a = [:foo, 'bar', 2]
a << :baz # => [:foo, "bar", 2, :baz]
Appends object as one element, even if it is another Array:
a = [:foo, 'bar', 2]
a1 = a << [3, 4]
a1 # => [:foo, "bar", 2, [3, 4]]
 
               VALUE
rb_ary_push(VALUE ary, VALUE item)
{
    long idx = RARRAY_LEN((ary_verify(ary), ary));
    VALUE target_ary = ary_ensure_room_for_push(ary, 1);
    RARRAY_PTR_USE_TRANSIENT(ary, ptr, {
        RB_OBJ_WRITE(target_ary, &ptr[idx], item);
    });
    ARY_SET_LEN(ary, idx + 1);
    ary_verify(ary);
    return ary;
}
            

Was this page useful?