Last active
December 14, 2015 10:09
-
-
Save benolee/5069861 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # slide 77 from waza talk | |
| # method definition with static scope, class eval'd in a string | |
| # Environment | |
| class Foo | |
| hello = "world!" | |
| define_method("foo") { hello } | |
| class_eval "def bar; hello; end" | |
| end | |
| x = Foo.new | |
| x.foo # => "world!" | |
| x.bar # => NameError | |
| # method definition with closure, class_eval'd in a string | |
| class Foo | |
| hello = "world!" | |
| define_method("foo") { hello } | |
| class_eval 'define_method("bar") { hello }' | |
| end | |
| x = Foo.new | |
| x.foo # => "world!" | |
| x.bar # => "world!" | |
| # RUBY_VERSION 1.9.2 | |
| # <3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment