开发者

Why begin/rescue/else behaves differently on 1.9.2 and 1.8.7

开发者 https://www.devze.com 2023-03-14 23:13 出处:网络
I am working with t开发者_JAVA技巧he method mm. In ruby 1.9.2 it behaves weird, instead of the expected result 1.9.2=>10 I am getting

I am working with t开发者_JAVA技巧he method mm. In ruby 1.9.2 it behaves weird, instead of the expected result 1.9.2=>10 I am getting

ELSE **
1.9.2=>8

Any idea of what is going on?

class A

 def mm(data)
   begin
     send_len = data
     return send_len
   rescue Exception
     STDOUT.write("Rescue *#{$!}*\n")
   else
     STDOUT.write("ELSE *#{$!}*\n")
   end
 end

end # class A

a = A.new
print "#{RUBY_VERSION}=>#{a.mm(10)}\n"

With 1.8.7 I get the expected result:

1.8.7=>10


It's an open bug in Ruby. There is a discussion, though, whether it should behave like it behaved in 1.8 or as it does in 1.9.

Matz, the author of Ruby, believes that it should behave as in 1.8.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号