Skip to content

Instantly share code, notes, and snippets.

@unnu
Created February 3, 2012 13:47
Show Gist options
  • Save unnu/1730245 to your computer and use it in GitHub Desktop.
Save unnu/1730245 to your computer and use it in GitHub Desktop.
More ruby scope bewares
class A
def foo
1
end
def beware_1
puts "beware_1"
p foo # -> 1
foo = foo
p foo # -> nil
end
def beware_2
puts "beware_2"
p defined? haa # -> nil
if false
haa = 2
end
p defined? haa # -> "local-variable"
end
def beware_3
puts "beware_3"
if false
@boo = 2
end
p defined? @boo # -> nil
@boo = 2
p defined? @boo # -> "instance-variable"
end
end
A.new.beware_1
A.new.beware_2
A.new.beware_3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment