Hegwin.Me

溯洄从之,道阻且长。溯游从之,宛在水中央。

Ruby 2.5 允许在do/end中使用rescue

In Ruby 2.4

(-1).upto(1).each do |i|
  p 8 / i
rescue e
  p e
end

You will get SyntaxError: unexpected keyword_rescue, expecting keyword_end.

In Ruby 2.5

(-1).upto(1).each do |i|
  p 8 / i
rescue e
  p e
end

You will get:

-8
#<ZeroDivisionError: divided by 0>
8

Tags:

Posted on: 2018-01-31

Back