Pregunta

I am trying to store a block with retry statement, but am getting a syntax error: Invalid retry. How do I store it right?

retries = 3
proc = Proc.new do
  if retries > 0
    p " Retries left: #{retries}"
    retries -= 1
    retry
  end
end
begin
  ...
rescue SomeErrorOne
  proc.call
rescue SomeErrorTwo
  proc.call
end
¿Fue útil?

Solución

Try to change the retry to redo. I think some changes were made in Ruby 1.9 as the retry keyword was abused.

The difference can be found here: http://rubyquicktips.com/post/1122838559/redo-vs-retry See the comment at the bottom.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top