Last active
October 29, 2015 21:04
-
-
Save burningTyger/d292381727116631d4c7 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
| require "delegate" | |
| module X | |
| def initialize(*) | |
| super | |
| __getobj__.class.instance_methods(false).each do |meth| | |
| define_singleton_method(meth) { __getobj__.send(meth) || "Is nil"} | |
| end | |
| end | |
| end | |
| class A < SimpleDelegator | |
| include X | |
| end | |
| class B | |
| def hi | |
| "hi" | |
| end | |
| def ho | |
| end | |
| end | |
| b=B.new | |
| a=A.new(b) | |
| puts a.hi | |
| puts a.ho | |
| class C | |
| def hi | |
| end | |
| def ho | |
| "ho" | |
| end | |
| end | |
| c=C.new | |
| a=A.new(c) | |
| puts a.hi | |
| puts a.ho |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment