Created
January 4, 2010 16:00
-
-
Save fronx/268611 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 Object | |
| def bury(class_or_module_name) | |
| Object.instance_eval { remove_const class_or_module_name.to_sym } | |
| end | |
| end | |
| # Example for class "self inheritance" | |
| class Abc | |
| def foo | |
| "foo" | |
| end | |
| end | |
| class Abc < bury(:Abc) | |
| def foo | |
| puts super | |
| end | |
| end | |
| Abc.new.foo | |
| # Example for module "self inheritance" | |
| module Xyz | |
| def bar | |
| "bar" | |
| end | |
| end | |
| BuriedXyz = bury(:Xyz) | |
| module Xyz | |
| include BuriedXyz | |
| def bar | |
| puts super | |
| end | |
| end | |
| class XyzTest | |
| include Xyz | |
| end | |
| XyzTest.new.bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment