I would like to implement something with a rescue-like syntax.
begin raise "Failed" rescue Exception => e puts e end This works, and e is assigned to the corresponding value. But used in a method, this will raise an exception saying that e is undefined. In other words, how can rescue assigns something to e this way without throwing an undefined error?
class MyClass def to_s "hello" end end def my_method puts e.to_s end my_method(MyClass => e) #=> undefined local variable or method `e' for main:Object