Created
November 25, 2012 04:39
-
-
Save rauchy/4142419 to your computer and use it in GitHub Desktop.
Blocks In-depth: Scope
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
a = 1 | |
Foo = Class.new do | |
# a == 1 here | |
b = 2 | |
define_method(:bar) do | |
# a == 1 here, b == 2 here | |
c = 3 | |
end | |
define_method(:baz) do | |
# a == 1 here, b == 2 here | |
# c is undefined here | |
d = 4 | |
end | |
# a == 1 here, b == 2 here | |
# c & d are undefined here | |
end |
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
a = 1 | |
class Foo | |
# a is undefined here | |
b = 2 | |
def bar | |
# a & b are undefined here | |
c = 3 | |
end | |
def baz | |
# a, b & c are undefined here | |
d = 4 | |
end | |
# a, c & d are undefined here | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment