/*
 *  call-seq:
 *     enum.first      -> obj or nil
 *     enum.first(n)   -> an_array
 *  
 *  Returns the first element, or the first +n+ elements, of the enumerable.
 *  If the enumerable is empty, the first form returns <code>nil</code>, and the
 *  second form returns an empty array.
 *     
 */

static VALUE
enum_first(int argc, VALUE *argv, VALUE obj)
{
    VALUE n, ary[2];
    
    rb_scan_args(argc, argv, "01", &n);

    if (argc == 0) {
        ary[0] = ary[1] = Qnil;
    }
    else {
        ary[0] = n;
        ary[1] = rb_ary_new2(NUM2LONG(n));
    }
    rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)ary);

    return ary[1];
}