Forum: Ruby iterative question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E13ba8e702211be152c640df2d8e141f?d=identicon&s=25 joe (Guest)
on 2006-06-08 16:31
hi all
 how to do a iterative for Time object,
 i.e.
 i wanna  iterative from 2000/05/05 to now, output to a array

regards
5da4c52f43677f395aff5bde775593c2?d=identicon&s=25 Daniel Schierbeck (dasch)
on 2006-06-08 16:47
(Received via mailing list)
joe wrote:
>  how to do a iterative for Time object,
>  i.e.
>  i wanna  iterative from 2000/05/05 to now, output to a array

   (time_a..time_b).to_a


Daniel
23172b6630dc631a134c9bad2fec2a39?d=identicon&s=25 Chris (Guest)
on 2006-06-08 16:56
joe wrote:
> hi all
>  how to do a iterative for Time object,
>  i.e.
>  i wanna  iterative from 2000/05/05 to now, output to a array
>
> regards

Date supports iteration:

startDate = Date.parse('2000/05/05')
days = []
startDate.upto(Date.today){|day| days << day}

cheers
This topic is locked and can not be replied to.