有人可以检查我注意到的这种行为吗?
如果您没有为局部变量分配任何内容并尝试将其打印出来,则会按预期生成异常。如果您在无法访问的代码路径中分配局部变量,则它可以工作。应该是这样吗?
def a
# Should generate an error because foobar is not defined.
puts foobar
end
def b
# This block never is run but foobar is entered into the symbol table.
if false
foobar = 123
end
# This succeeds in printing nil
puts foobar
end
begin; a; rescue Exception => e; puts "ERROR: #{e.message}"; end
begin; b; rescue Exception => e; puts "ERROR: #{e.message}"; end