2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
|
# File 'ext/list/list.c', line 2332
static VALUE
list_cycle(int argc, VALUE *argv, VALUE self)
{
VALUE nv = Qnil;
item_t *c;
long n;
RETURN_SIZED_ENUMERATOR(self, argc, argv, list_cycle_size);
rb_scan_args(argc, argv, "01", &nv);
if (NIL_P(nv)) {
n = -1;
} else {
n = NUM2LONG(nv);
if (n <= 0) return Qnil;
}
while (0 < LIST_LEN(self) && (n < 0 || 0 < n--)) {
LIST_FOR(self, c) {
rb_yield(c->value);
if (list_empty_p(self)) break;
}
}
return Qnil;
}
|