Last active
December 23, 2015 06:09
-
-
Save kke/6592421 to your computer and use it in GitHub Desktop.
What's going on here?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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