Created
July 2, 2010 17:09
-
-
Save toothrot/461620 to your computer and use it in GitHub Desktop.
blocks are funky.
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
outside = "foo" | |
classy = Class.new do | |
define_method(:get_thing) do | |
outside | |
end | |
def get_thing_with_def | |
outside | |
end | |
define_method(:curious) do | |
self | |
end | |
def def_curious | |
self | |
end | |
end | |
classy.new.get_thing # => "foo" | |
classy.new.get_thing_with_def # => NameError | |
classy.new.curious #=> classy instance | |
classy.new.def_curious #=> classy instance | |
outside = "bar" | |
classy.new.get_thing # => "bar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment