有人可以检查一下我注意到的这种行为吗?
如果您没有为局部变量分配任何内容并尝试将其打印出来,则会按预期生成异常.如果在无法访问的代码路径中分配局部变量,则它可以正常工作.应该是这样的吗?
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
162 次 |
| 最近记录: |