step(p1, p2 = v2)
public
Iterates evaluation of the given block, which takes a date object. The
limit should be a date object.
Date.new(2001).step(Date.new(2001,-1,-1)).select{|d| d.sunday?}.size
static VALUE
d_lite_step(int argc, VALUE *argv, VALUE self)
{
VALUE limit, step, date;
rb_scan_args(argc, argv, "11", &limit, &step);
if (argc < 2)
step = INT2FIX(1);
#if 0
if (f_zero_p(step))
rb_raise(rb_eArgError, "step can't be 0");
#endif
RETURN_ENUMERATOR(self, argc, argv);
date = self;
switch (FIX2INT(f_cmp(step, INT2FIX(0)))) {
case -1:
while (FIX2INT(d_lite_cmp(date, limit)) >= 0) {
rb_yield(date);
date = d_lite_plus(date, step);
}
break;
case 0:
while (1)
rb_yield(date);
break;
case 1:
while (FIX2INT(d_lite_cmp(date, limit)) <= 0) {
rb_yield(date);
date = d_lite_plus(date, step);
}
break;
default:
abort();
}
return self;
}