So new method are added just fine, however a method I would like to redefine stays the same. Is it how it was supposed to work? And how to actually do redefine a method? Should there be any tricks involved, like aliasing?
So new method are added just fine, however a method I would like to
redefine stays the same. Is it how it was supposed to work? And how to
actually do redefine a method? Should there be any tricks involved, like
aliasing?
Test.ancestors #==> [Test, Mixin, Object, Kernel]
So actually, your Test#foo is replacing Mixin#foo, because Test occurs
before Mixin on the method search path.
So new method are added just fine, however a method I would like to
redefine stays the same. Is it how it was supposed to work?
Yes, this is how it’s supposed to work. When you mix a module into a
class, the module more-or-less acts as a superclass of the class it’s
mixed-into. So for your example, Test#foo is redefining the Module#foo
method.
Thanks to everybody for explanation. My mistake was to expect something
happen magically. Now that I think how the whole mixin mechanism works I see
why modules and classes in my example behaved that way. It explains
everything. The bottom line is: when you want something done – do it
yourself ;-), that what append_features is there for.
Gennady.
(Thank you Lyle, too, for the off-list suggestion)
So new method are added just fine, however a method I would like to
redefine stays the same. Is it how it was supposed to work? And how to
actually do redefine a method? Should there be any tricks involved, like
aliasing?
Test.ancestors #==> [Test, Mixin, Object, Kernel]
So actually, your Test#foo is replacing Mixin#foo, because Test occurs
before Mixin on the method search path.