Created
April 4, 2015 03:42
-
-
Save activefx/5460d9236ba0ba7f1800 to your computer and use it in GitHub Desktop.
Revisions
-
activefx created this gist
Apr 4, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ 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