Created
April 4, 2015 03:42
-
-
Save activefx/5460d9236ba0ba7f1800 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
class Example | |
def make_method(&block) | |
line_no = __LINE__; method_defs = %{ | |
def dynamic_method | |
#{block}.call(1) | |
end | |
} | |
instance_eval method_defs, __FILE__, line_no | |
end | |
end | |
example = Example.new | |
example.make_method do |n| | |
n + 1 | |
end | |
# expect to be 2 | |
example.dynamic_method | |
#=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment