mixology
mixology copied to clipboard
Feature request: add mixin hook similar to method_added and included
module Mixology def mixin(mod) unmix mod reset_method_cache IncludedModule.new(mod).attach_to metaclass reset_method_cache mixed_in(self) self end
def unmix(mod_to_unmix)
last_super = metaclass
this_super = metaclass.direct_superclass
while this_super
break if this_super == self.class
if (this_super == mod_to_unmix ||
this_super.respond_to?(:module) && this_super.module == mod_to_unmix)
reset_method_cache
last_super.superclass = this_super.direct_superclass
reset_method_cache
mixed_out(self)
return self
else
last_super = this_super
this_super = this_super.direct_superclass
end
end
mixed_out(self)
self
end
def mixed_out(obj) end
def mixed_in(obj)
end
...
But trying to get it to work on my local machine doesn't seem to work!? I really need such hooks... could I somehow use the included hook instead?
This will do what you want: http://gist.github.com/240872 I'll try to get something in mixology officially later.