From: Daniel Schierbeck Date: 2005-11-24T06:47:26+09:00 Subject: Re: pattern: auto-running module init code Phil Tomson wrote: > In article <4384cee3$0$1760$edfadb0f@dread11.news.tele.dk>, > Daniel Schierbeck wrote: >> Phil Tomson wrote: >>> I do kind of like your solution, but it does mean that the implementor of the >>> module needs to know to define an 'initialized' method to make the mechanism >>> work. >> That's no different from Module#included and Class.inherited. I think >> the method belongs in the module. >> >>> What if you just test for mod.respond_to? :initialize ? I suppose the >>> problem with that would be if the user of the module did happen to include >>> 'super' in their constructor - if they did then the module initialization >>> would be called twice. >> Yeah, and there would be the problem that multiple included modules >> would override each other's `initialize' methods (as would the including >> class.) > > Actually, with your approach where you look for all the included modules and > call each of their 'initialize' methods it shouldn't be a problem since you > are bypassing the super mechanism. > > Phil Yeah, but calling a module's method without first including the module in a class and then instantiating that class isn't easy. And for some reason my Object#method seems to fail. Weird... Cheers, Daniel