Last active
May 11, 2020 15:34
-
-
Save hanachin/52625cdcdcca6608bfb2b46af6672b2b to your computer and use it in GitHub Desktop.
Revisions
-
hanachin revised this gist
May 11, 2020 . 1 changed file with 0 additions and 1 deletion.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 @@ -18,7 +18,6 @@ def respond_to_missing?(*); true; end end } def plus_one(x) x + 1 end -
hanachin created this gist
May 11, 2020 .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,31 @@ require 'binding_of_caller' using Module.new { refine(Array) do def map(&block) caller = binding.of_caller(1) cleanroom = Class.new(BasicObject) do def respond_to?(*); true; end def respond_to_missing?(*); true; end define_method(:method_missing) do |name,*| caller.method(name) end end super(&cleanroom.new.instance_eval(&block)) end end } def plus_one(x) x + 1 end def double(x) x * 2 end pp [1, 2, 3, 4].map { plus_one >> double } #=> [4, 6, 8, 10]