誰かが私が気づいているこの動作について私をチェックしてもらえますか?
ローカル変数に何も割り当てずに出力しようとすると、予想どおり例外が生成されます。到達不能なコード パスにローカル変数を割り当てると、機能します。これは事実ですか?
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