Skip to content

Feature request: add mixin hook similar to method_added and included #1

@kristianmandrup

Description

@kristianmandrup

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions