Created
September 21, 2009 20:11
-
-
Save msassak/190519 to your computer and use it in GitHub Desktop.
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
# This will work | |
x = nil | |
a = lambda { | |
if x.nil? | |
"x is nil, as it should be" | |
else | |
"somehow x = #{x}" | |
end | |
} | |
b = lambda { | |
x = "what what what?" | |
"set x in b" | |
} | |
puts a.call | |
puts b.call | |
puts a.call | |
# This will raise 'undefined local variable or method `x' for main:Object (NameError)' | |
x = nil | |
def a_meth | |
if x.nil? | |
"x is nil, as it should be" | |
else | |
"somehow x = #{x}" | |
end | |
end | |
def b_meth | |
x = "what what what?" | |
"set x in b" | |
end | |
puts a_meth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment