Carlos
11/11/2004 1:36:00 PM
[Bill Atkins <batkins57@gmail.com>, 2004-11-11 13.49 CET]
> > array.each do |e|
> > if (today_is_christmas)
> > array += ["Hello"]
> > retry
> > end
> > end
> How does this work? Does 'retry' recall the method associated with its block?
Yes, and re-evaluates its arguments (if any).
Inside a method, it seems to recall the method (re-evaluating arguments)
only if the method has a block, altough you are not inside it. Didn't test
that much.
def repeat (what, test_until)
retry if !test_until
end
s = ""
repeat(s << "x", s.length > 5)
puts s
retry.rb:2:in `repeat': retry outside of rescue clause (LocalJumpError)
from retry.rb:6
But:
def repeat (what, test_until)
retry if !test_until
end
s = ""
repeat(s << "x", s.length > 5) {} # <-- note block
puts s
#-> xxxxxx
Greetings.