Created
April 23, 2011 23:05
-
-
Save postmodern/939069 to your computer and use it in GitHub Desktop.
A Mixin module, that configures other modules so they can be included or extended.
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 Mixin | |
def self.included(base) | |
base.module_eval do | |
def self.mixin(*modules,&block) | |
@mixin_modules = modules | |
@mixin_block = block | |
def self.included(base) | |
unless @mixin_modules.empty? | |
base.send(:include,*@mixin_modules) | |
end | |
if @mixin_block | |
base.module_eval(&@mixin_block) | |
end | |
end | |
def self.extended(base) | |
unless @mixin_modules.empty? | |
base.send(:extend,*@mixin_modules) | |
end | |
if @mixin_block | |
base.instance_eval(&@mixin_block) | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment