Question on Ranges

Why am I not able to do this?

x=Time.now
y=Time.now + 1.year
(x..y).step(1.week)

The step function just goes seems to hang in a loop. Shouldn't it
return the remaining weeks in the current year (ignoring the start of
week)?

It's not hanging, it's stepping through the range. You need to pass
it a block to tell it what to do on each step.

(x..y).step(1.week) { |x| puts x }

Best.
Mike

In my actual code, I was trying to store the results in an array and
it just takes forever. Does it work properly for you? Even if I
iterate through the array members using a block, each block takes a
*long* time to display something.

Ruby --> ruby 1.8.6 (2008-03-03 patchlevel 114) [x86_64-linux]
Rails --> Rails 2.1.0
OS --> Fedora 7 x64

I tried this on a fresh rails app as well.

Thanks,
Mukund

In my actual code, I was trying to store the results in an array and
it just takes forever. Does it work properly for you? Even if I
iterate through the array members using a block, each block takes a
*long* time to display something.

Ruby --> ruby 1.8.6 (2008-03-03 patchlevel 114) [x86_64-linux]
Rails --> Rails 2.1.0
OS --> Fedora 7 x64

Not working at all or just very slow? With a non numeric range, ruby
calls the succ method as many times as needed per iteration (ie 600000
or so in this case) which could conceivably be slow. You might be
better off stepping through a numeric offset that you can add to the
origin point, ie

(0..1).step(1.week) do |increment|
   #do something to x.increment
end

I have an inkling that neither this (not the slow method) will handle
dst changes properly as they both force 1.week to an integer.
Fred

Just incredibly slow. I ended up doing it the hard/right way but
converting time to integer seconds since epoch at the expense of
readability.