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
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” [email protected]
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
[email protected]
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!