So, I was using what I wrote above, and realized that, should the ending
value of your time range not fall exactly on the interval specified, it
will only show the last interval before the end of the range... and
sometimes, that''s not what I want. So, I did this
class Range
def each(options = {}, &block)
val = self.begin
while val < self.end
yield val
val = val.succ
end
yield self.end if self.end == val || options[:always_include_last]
end
end
Now, when I''m doing my iteration over the range, I can specify
range.each :always_include_last => true do |time|
#do stuff with the time here
end
And it will always include the last value... even if it''s only 5
minutes
from your last one, and you told it to do 30 minute intervals.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---