Jacob Fugal
12/9/2005 10:06:00 PM
On 12/9/05, mental@rydia.net <mental@rydia.net> wrote:
> Quoting mental@rydia.net:
>
> > How do I make next, retry, and break work as expected?
>
> Sorry, s/retry/redo/.
Like Gabriele said in the other thread, they seem to already...
$ cat test.rb
lukfugl@falcon:~$ cat test.rb
class MyArray
include Enumerable
def initialize( *ary )
@ary = ary
end
def each
@ary.each { |el| yield el }
end
end
def test( ary, *sequence )
puts "### #{ary.class}, #{sequence.inspect} ###"
ary.each do |el|
puts el
case sequence.shift
when :next then next
when :retry then retry
when :redo then redo
when :break then break
end
end
end
ary1 = [ 1, 2, 3, 4, 5 ]
ary2 = MyArray.new( *ary1 )
test( ary1, :next, :retry, :next, :next, :redo, :redo, :break )
test( ary2, :next, :retry, :next, :next, :redo, :redo, :break )
$ ruby test.rb
### Array, [:next, :retry, :next, :next, :redo, :redo, :break] ###
1
2
1
2
3
3
3
### MyArray, [:next, :retry, :next, :next, :redo, :redo, :break] ###
1
2
1
2
3
3
3
Jacob Fugal