Rewinding a block

Hi,

I’m looking at a way to rewind a block.

I have a class with an implemented each function.

myclass.each { |t|
do thingks with t
}

I’ve written a myclass.rewind function which will reset the counter the
each function is stepping through in the block, so for instance, with an
array…

myarrayclass.each { |t|
puts t
myarrayclass.rewind if t == 5
}

then it would produce a never ending loop of:
1
2
3
4
5

however, I would like the rewind method to instantly start over the
process of stepping through the block, becase as you can see, if there
was an exit right after the rewind, that would still have been reached.

Can I somehow make the rewind also call ‘next’ ?

I could of course write,

if (t == 5)
myarrayclass.rewind
next
end

but I would like to know if it’s possible.

Daniel

···


Mar 19 Swallows return to Capistrano
Mar 19 St. Joseph’s Day, obeserved in Colombia, Costa Rica, Holy See,
Liechtenstein, San Marino, Spain, Venezuela
Mar 19 Tree Planting Day in Lestho

Hi,

···

In message “rewinding a block” on 03/03/20, Daniel Bretoi lists@debonair.net writes:

I’m looking at a way to rewind a block.

Try “retry”.

						matz.