Created
February 3, 2012 13:47
-
-
Save unnu/1730245 to your computer and use it in GitHub Desktop.
More ruby scope bewares
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
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