开发者

Ruby-Proper Usage of the Date.step() method

I have been trying to use the step() method on Date object to retrieve the previous 2 dates from the current date as follows:

  date_d.step(2, step=-2){|d|
    puts d        
  }

where 2 is the limit and step is the number o开发者_开发百科f steps backward or forward.

I have done this in accordance with the Documentation given here: Date.step()

This code snippet goes into an infinite loop and then outputs the date non-stop (backwards)

There doesn't seem to be enough documentation for this method and i am not finding solutions online as well.

Please help me out with this.


the limit parameter is the date where the loop stops not the number of days or iterations. so for example

date_d = Date.parse( '2010-08-01' )
date_d.step(date_d - 4 , step=-2){|d|
   puts d        
}

will output

2010-08-01
2010-07-30
2010-07-28
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜