In article <4384be41$0$1773$edfadb0f / dread11.news.tele.dk>,
Daniel Schierbeck  <daniel.schierbeck / gmail.com> wrote:
>Phil Tomson wrote:
>> In article <43846a75$0$1813$edfadb0f / dread11.news.tele.dk>,
>> Daniel Schierbeck  <daniel.schierbeck / gmail.com> wrote:
>> 
>>> Ideally, there would be a method hook that was called when a class 
>>> including the module was instantiated.
>>>
>>>   module Fooable
>>>     def self.initialized(obj, *args, &block)
>>>       puts "A class including Fooable has been instantiated!"
>>>       obj.do_something(*args) # whatever
>>>     end
>>>   end
>> 
>> But as Sean pointed out we essentially get the same behavior by calling 
>> 'super' somewhere in the including class's constructor.
>> 
>> Phil
>
>Yeah, but that requires the including class to add code to the 
>`initialize' method, some I don't think should be necessary for a module 
>to function. I think that the behaviour of a module should be kept 
>within that module, unless it needs some specific methods (like 
>Enumerable needs `each').

True, that's essentially what I was trying to get around (having to know to 
explicitly call 'super' or some other initialization method defined in the 
module. 

>
>The only issue I have with my current model (see my other post for an 
>implementation) is that it might be better for the module initializer to 
>be an instance method, instead of a module method.
>
>   module Fooable
>     def self.initialized(obj, *args, &block); end
>     # versus
>     def initialized(*args, &block); end
>   end
>
>And maybe it should be called `instantiated' instead of `initialized', 
>though that doesn't really make much of a difference for me.


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.  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.

Phil