Skip to content

Instantly share code, notes, and snippets.

@kke
Last active December 23, 2015 06:09
Show Gist options
  • Save kke/6592421 to your computer and use it in GitHub Desktop.
Save kke/6592421 to your computer and use it in GitHub Desktop.
What's going on here?
begin
puts foo.inspect # This raises an exception
rescue
puts $!.message
end
if false
foo = 100
else
puts foo.inspect # This raises nothing (even without the above begin..rescue block)
end
# Or even:
if false
goo = 100
end
puts goo.inspect
# But it does raise if the if..else order is reversed
if true
puts bar.inspect
else
bar = 100
end
# $ ruby foo.rb
# undefined local variable or method `foo' for main:Object
# nil
# nil
# undefined local variable or method `bar' for main:Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment