Created
October 7, 2015 17:15
-
-
Save osyo-manga/6eaa17d66b61e8846446 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
| module MethodWrapper | |
| def wrap name, &block | |
| prepend(Module.new do | |
| define_method name do | |
| super_ = proc { super() } | |
| Object.new.instance_eval do | |
| define_singleton_method :super_ do | |
| super_.() | |
| end | |
| instance_eval &block | |
| end | |
| end | |
| end) | |
| end | |
| end | |
| class X | |
| extend MethodWrapper | |
| def homu | |
| p :homu | |
| end | |
| wrap :homu do | |
| p :mami | |
| super_() | |
| end | |
| end | |
| X.new.homu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment