From: Robert Klemme Date: 2009-04-20T01:10:13+09:00 Subject: Re: ruby1.9 and the retry keyword On 19.04.2009 16:20, Yoann Guillot wrote: > It seems that the 'retry' keyword is not supported anymore in ruby1.9 to > restart a running iteration from the beginning. This cannot be, "retry" works in 1.9.1: [robert@ora01 ~]$ irb19 irb(main):001:0> i = 5 => 5 irb(main):002:0> begin irb(main):003:1* puts i irb(main):004:1> raise "foo" irb(main):005:1> rescue Exception irb(main):006:1> i -= 1 irb(main):007:1> retry if i > 0 irb(main):008:1> end 5 4 3 2 1 => nil irb(main):009:0> RUBY_VERSION => "1.9.1" irb(main):010:0> > Is there a way to achieve the old behavior, preferably in a 1.8 compatible > way ? > > $ ruby1.8 -ve '[1, 2].each { puts "bla" ; retry }' > ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux] > bla > bla > bla > ^C "retry" without "rescue" seems pointless to me. As far as I can see "retry"'s main purpose is repetition in case of exceptions. The use that you demonstrate looks like a untypical and probably unwanted idiom which accidentally happened to work in 1.8.* to me. > $ ruby1.9 -ve '[1, 2].each { puts "bla" ; retry }' > ruby 1.9.2dev (2009-04-19) [i686-linux] > -e:1: Invalid retry > -e: compile error (SyntaxError) Apparently the _syntax_ was changed to allow "retry" only in "rescue" clauses - which makes perfectly sense for me. I am not the definitive source but to me it looks like 1.9 fixes a misbehavior of 1.8 - if that's the case I would not want to reintroduce this just to make 1.9 more compatible to 1.8. In fact, 1.9 purposefully *does* have some incompatibilities. Kind regards robert