From: Christoph Rippel Date: 2000-12-20T03:24:24+09:00 Subject: [ruby-talk:7702] (Maybe) a correction for Programming Ruby -----Original Message----- From: dave@thomases.com [mailto:dave@thomases.com]On Behalf Of Dave Thomas Sent: Monday, December 18, 2000 11:06 AM To: ruby-talk ML Subject: [ruby-talk:7594] Re: Question about #append_features >It's described briefly at > > http://www.rubycentral.com/ref/ref_c_module.html#append_features > >It's the method called when you say 'include'. In this case, Singleton >is hooking itself, so that when it gets included in a class it can >work its magic. Actually the description in the library reference does not make since to me. >>append_features( aModule) -> mod >>The constants and methods of aModule are added to the current module if >>aModule has not already been added to the current module or one of its >>ancestors. Also see Module#include on page 350. If I run module A def A.append_features(aModule) p "module A was included in #{aModule} but #{aModule}.foo was not defined" end def foo end end class B include A end x = B.new x.foo I end up with >>"module A was included in B but B.foo was not defined" >>rr.rb:14: undefined method `foo' for # (NameError) So maybe this should read as: ''append_features( aModule) -> mod The private method #append_features is called when self, the current Module, is included in the Module aModule. The default behavior is to include constants, methods, variables and modules variables of self to aModule if self has not been added to aModule or one of its ancestors. Also see ... '' Christoph Ps. technically speaking this is not the whole story since the implementation of #append_features is also responsible for the structure of the ancestor chain of aModule (which is not trivial in all cases since circular mixin's of many modules sometimes lets to a very long and complicated ancestor chain) and the ancestor chain is different if I redefine #append_features.