Created
May 19, 2009 11:03
-
-
Save jcoglan/114042 to your computer and use it in GitHub Desktop.
This file contains 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
## Abstraction for common pattern of using Module#included to | |
## add class methods to the host class. | |
class Module | |
def extends_host_with(class_methods) | |
@_extension_module = class_methods | |
def included(base) | |
base.extend(const_get(@_extension_module)) | |
end | |
end | |
end | |
## Example | |
module MyMod | |
extends_host_with :ClassMethods | |
def an_instance_method; end | |
module ClassMethods | |
def a_class_method; end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment