Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Date#step

step(limit, step = 1){|date| ... } → self

Calls the block with specified dates; returns self.

  • The first date is self.

  • Each successive date is date + step, where step is the numeric step size in days.

  • The last date is the last one that is before or equal to limit, which should be a Date object.

Example:

Example
limit = Date.new(2001, 12, 31)
Date.new(2001).step(limit){|date| p date.to_s if date.mday == 31 }

Output:

Example
"2001-01-31"
"2001-03-31"
"2001-05-31"
"2001-07-31"
"2001-08-31"
"2001-10-31"
"2001-12-31"

Returns an Enumerator if no block is given.

See also #start #strftime #saturday? #succ also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0