Skip to content

Instantly share code, notes, and snippets.

@postmodern
Created April 23, 2011 23:05
Show Gist options
  • Save postmodern/939069 to your computer and use it in GitHub Desktop.
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.
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