Forum: Ruby on Rails Counting up in 5's or something similar.

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.
Ruby on Rails: Talk (Guest)
on 2009-06-06 01:05
(Received via mailing list)
Hi

I'm sure I've read somewhere that you can count up in 'jumps' using
ruby?

I've got two times and I want to basically go up in 15 minute jumps
without using the whole for loop thing.

Any helpful ideas? All my ruby books are in storage and I can't find
anything on google ...but then I'm not sure what I'm looking for!

Thanks in advance.

Code:

<%- (@info[0][1].. @info[0][2]).???? do %>

Darren
Franco C. (Guest)
on 2009-06-06 01:21
(Received via mailing list)
You probably talk about the step function (http://www.ruby-doc.org/
core/classes/Numeric.src/M000189.html). Always look first the Ruby
API.

Regards.

Franco C..

On Jun 5, 6:04 pm, "Ruby on Rails: Talk" <removed_email_address@domain.invalid>
Rob B. (Guest)
on 2009-06-06 01:24
(Received via mailing list)
On Jun 5, 2009, at 5:04 PM, Ruby on Rails: Talk wrote:

> anything on google ...but then I'm not sure what I'm looking for!
>
> Thanks in advance.
>
> Code:
>
> <%- (@info[0][1].. @info[0][2]).???? do %>
>
> Darren

Something like Numeric#step

irb> require 'rubygems'
=> true
irb> require 'activesupport'
=> true
irb> start_time = 10.minutes.from_now
=> Fri Jun 05 17:26:49 -0400 2009
irb> end_time = 4.hours.since start_time
=> Fri Jun 05 21:26:49 -0400 2009
irb> start_time.to_i.step(end_time.to_i, 15.minutes) do |sec| puts
Time.at(sec); end
Fri Jun 05 17:26:49 -0400 2009
Fri Jun 05 17:41:49 -0400 2009
Fri Jun 05 17:56:49 -0400 2009
Fri Jun 05 18:11:49 -0400 2009
Fri Jun 05 18:26:49 -0400 2009
Fri Jun 05 18:41:49 -0400 2009
Fri Jun 05 18:56:49 -0400 2009
Fri Jun 05 19:11:49 -0400 2009
Fri Jun 05 19:26:49 -0400 2009
Fri Jun 05 19:41:49 -0400 2009
Fri Jun 05 19:56:49 -0400 2009
Fri Jun 05 20:11:49 -0400 2009
Fri Jun 05 20:26:49 -0400 2009
Fri Jun 05 20:41:49 -0400 2009
Fri Jun 05 20:56:49 -0400 2009
Fri Jun 05 21:11:49 -0400 2009
Fri Jun 05 21:26:49 -0400 2009
=> 1244237209

You have to go from Time => Fixnum => Time, but you can adjust to your
specifics.

-Rob

Rob B.    http://agileconsultingllc.com
removed_email_address@domain.invalid
Ruby on Rails: Talk (Guest)
on 2009-06-06 01:41
(Received via mailing list)
Yeah thanks!

Just after I posted it I remembered my pascal (or similar) days and
step came into mind ...

(@info[0][1].. @info[0][2]).step(15.minutes) do |i|

Seemed to do the trick nicely!
This topic is locked and can not be replied to.