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 of 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.
Ruby | DateTime now() function DateTime#now() : now() is a DateTime class method which returns a DateTime object denoting the given calendar date. Return: DateTime object denoting the given calendar date.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With