F
Farrel Lifson
I've been playing around with rescue expressions and besides being put
on functions they also seem to work when defining classes (useful for
metaprogramming perhaps?)
irb(main):001:0> class Test
irb(main):002:1> raise
irb(main):003:1> rescue
irb(main):004:1> puts "Error"
irb(main):005:1> ensure
irb(main):006:1* puts "Cleaned up"
irb(main):007:1> end
Error
Cleaned up
However, why can they not be applied to do end blocks?
irb(main):016:0> [1,2,3].each do |num|
irb(main):017:1* num.upcase
irb(main):018:1> rescue
irb(main):019:1> puts "Error"
irb(main):020:1> ensure
irb(main):021:1* puts "Clened up"
irb(main):022:1> end
SyntaxError: compile error
(irb):18: syntax error
(irb):20: syntax error
from (irb):22
Farrel
on functions they also seem to work when defining classes (useful for
metaprogramming perhaps?)
irb(main):001:0> class Test
irb(main):002:1> raise
irb(main):003:1> rescue
irb(main):004:1> puts "Error"
irb(main):005:1> ensure
irb(main):006:1* puts "Cleaned up"
irb(main):007:1> end
Error
Cleaned up
However, why can they not be applied to do end blocks?
irb(main):016:0> [1,2,3].each do |num|
irb(main):017:1* num.upcase
irb(main):018:1> rescue
irb(main):019:1> puts "Error"
irb(main):020:1> ensure
irb(main):021:1* puts "Clened up"
irb(main):022:1> end
SyntaxError: compile error
(irb):18: syntax error
(irb):20: syntax error
from (irb):22
Farrel