/*
* call-seq:
* e.with_index {|(*args), idx| ... }
* e.with_index
*
* Iterates the given block for each elements with an index, which
* start from 0. If no block is given, returns an enumerator.
*
*/
static VALUE
enumerator_with_index(VALUE obj)
{
struct enumerator *e;
VALUE memo = 0;
int argc = 0;
VALUE *argv = 0;
RETURN_ENUMERATOR(obj, 0, 0);
e = enumerator_ptr(obj);
if (e->args) {
argc = RARRAY_LEN(e->args);
argv = RARRAY_PTR(e->args);
}
return rb_block_call(e->obj, e->meth, argc, argv,
enumerator_with_index_i, (VALUE)&memo);
}