Skip to content

Instantly share code, notes, and snippets.

@jcoglan
Created May 19, 2009 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcoglan/114042 to your computer and use it in GitHub Desktop.
Save jcoglan/114042 to your computer and use it in GitHub Desktop.
## 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