first(*args)
public
Returns the first element, or the first n elements, of the array. If
the array is empty, the first form returns
nil, and the second form returns an empty array. See also Array#last for the opposite effect.
a = [ "q", "r", "s", "t" ]
a.first
a.first(2)
Show source
static VALUE
rb_ary_first(int argc, VALUE *argv, VALUE ary)
{
if (argc == 0) {
if (RARRAY_LEN(ary) == 0) return Qnil;
return RARRAY_AREF(ary, 0);
}
else {
return ary_take_first_or_last(argc, argv, ary, ARY_TAKE_FIRST);
}
}