I've been studying exceptions in Ruby, and have discovered some syntax that is not documented in the Pickaxe, nor anywhere obvious that I can find with Google.
Everyone knows about rescue clauses with begin/end. And most Ruby programmers probably know that you can use a rescue clause at the end of a method definition. What I was surprised to discover (by reading the parse.y grammar file in the source distribution) is that rescue clauses are also allowed at the end of class and module definitions.
This, for example, is legal Ruby:
class Test
def t
1
end
raise "foo"
rescue
p $!
else
p "Class Test defined without exceptions"
ensure
p "Exiting class Test"
end
p Test.new.t
I'm not sure when this would be useful, but it is legal, and it ought to be documented!



