mixology icon indicating copy to clipboard operation
mixology copied to clipboard

Feature request: add mixin hook similar to method_added and included

Open kristianmandrup opened this issue 15 years ago • 1 comments

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?

kristianmandrup avatar Nov 07 '09 16:11 kristianmandrup

This will do what you want: http://gist.github.com/240872 I'll try to get something in mixology officially later.

dan-manges avatar Nov 23 '09 03:11 dan-manges