first(...)
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.
a = [ "q", "r", "s", "t" ]
a.first
a.first(1)
a.first(3)
Show source
/*
* call-seq:
* array.first -> obj or nil
* array.first(n) -> an_array
*
* Returns the first element, or the first +n+ elements, of the array.
* If the array is empty, the first form returns <code>nil</code>, and the
* second form returns an empty array.
*
* a = [ "q", "r", "s", "t" ]
* a.first
* a.first(1)
* a.first(3)
*/
static VALUE
rb_ary_first(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
{
if (argc == 0) {
if (RARRAY(ary)->len == 0) return Qnil;
return RARRAY(ary)->ptr[0];
}
else {
return ary_shared_first(argc, argv, ary, Qfalse);
}
}