Skip to content

Instantly share code, notes, and snippets.

@msassak
Created September 21, 2009 20:11
Show Gist options
  • Save msassak/190519 to your computer and use it in GitHub Desktop.
Save msassak/190519 to your computer and use it in GitHub Desktop.
# 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