method
step
v2_6_3 -
Show latest stable
- Class:
Date
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 #=> 52
static VALUE
d_lite_step(int argc, VALUE *argv, VALUE self)
{
VALUE limit, step, date;
int c;
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;
c = f_cmp(step, INT2FIX(0));
if (c < 0) {
while (FIX2INT(d_lite_cmp(date, limit)) >= 0) {
rb_yield(date);
date = d_lite_plus(date, step);
}
}
else if (c == 0) {
while (1)
rb_yield(date);
}
else /* if (c > 0) */ {
while (FIX2INT(d_lite_cmp(date, limit)) <= 0) {
rb_yield(date);
date = d_lite_plus(date, step);
}
}
return self;
} Related methods
- Instance methods
- +
- -
- <<
- <=>
- ===
- >>
- ajd
- amjd
- as_json
- asctime
- ctime
- cwday
- cweek
- cwyear
- day
- day_fraction
- downto
- england
- eql?
- fill
- friday?
- gregorian
- gregorian?
- hash
- httpdate
- initialize_copy
- inspect
- inspect_raw
- iso8601
- italy
- jd
- jisx0301
- julian
- julian?
- ld
- leap?
- marshal_dump
- marshal_dump_old
- marshal_load
- mday
- mjd
- mon
- monday?
- month
- new_start
- next
- next_day
- next_month
- next_year
- nth_kday?
- prev_day
- prev_month
- prev_year
- rfc2822
- rfc3339
- rfc822
- saturday?
- start
- step
- strftime
- succ
- sunday?
- thursday?
- to_date
- to_datetime
- to_json
- to_s
- to_time
- tuesday?
- upto
- wday
- wednesday?
- xmlschema
- yday
- year
- Class methods
- _httpdate
- _iso8601
- _jisx0301
- _load
- _parse
- _rfc2822
- _rfc3339
- _rfc822
- _strptime
- _xmlschema
- civil
- commercial
- gregorian_leap?
- httpdate
- iso8601
- jd
- jisx0301
- json_create
- julian_leap?
- leap?
- new
- new!
- nth_kday
- ordinal
- parse
- rfc2822
- rfc3339
- rfc822
- strptime
- test_all
- test_civil
- test_commercial
- test_nth_kday
- test_ordinal
- test_unit_conv
- test_weeknum
- today
- valid_civil?
- valid_commercial?
- valid_date?
- valid_jd?
- valid_ordinal?
- weeknum
- xmlschema
- Private methods
-
hour -
min -
minute -
sec -
second -
wnum0 -
wnum1