Created
October 30, 2009 23:00
-
-
Save carllerche/222792 to your computer and use it in GitHub Desktop.
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
# 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_methods || []).each do |blk| | |
(class << base ; self ; end).class_eval(&blk) | |
end | |
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 ||= [] | |
@_class_methods << blk | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment