Skip to content

Instantly share code, notes, and snippets.

@carllerche
Created October 13, 2009 03:10
Show Gist options
  • Save carllerche/208940 to your computer and use it in GitHub Desktop.
Save carllerche/208940 to your computer and use it in GitHub Desktop.
# This is pretty evil, yeah... I know
class Module
alias old_append_features append_features
def append_features(base)
return false if base < self
(@_needed || []).each { |mod| base.send(:include, mod) }
(class << base ; self ; end).class_eval(&@_class_methods) if @_class_methods
old_append_features(base)
end
alias old_included included
def included(base = nil, &blk)
if block_given?
@_on_include = blk
else
base.class_eval(&@_on_include) if @_on_include
old_included(base)
end
end
def needs(*mods)
mods.each do |mod|
next if self < mod
@_needed ||= []
@_needed << mod
end
end
def class_methods(&blk)
@_class_methods = blk
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment