From: Jeff Rose Date: 2006-05-23T21:23:54+09:00 Subject: Re: initializing instance variables in a module Yukihiro Matsumoto wrote: > Hi, > > In message "Re: initializing instance variables in a module" > on Tue, 23 May 2006 00:51:35 +0900, Jeff Rose writes: > > |Is there a standard or correct way to initialize @foo_the_stuff in this > |example? > > This is not the answer, but I have been aware of this issue. I'm > planning to add method combination a la CLOS in the future to support > this issue. It is another option that adding a new hook like > 'module_initialize' which is called at instantiation time for all > modules. > > matz. That would do the trick, and it would probably make the AOP people very happy. But that is a bit different than an explicit module initialization method. Is there a reason you don't want module_initialize or something like that? CLOS does something like (defmethod rock :before ...), right? Any ideas on how the method combination would work in ruby? # Maybe using methods... module Rocker def pre_rock puts 'pre rock' end before :rock, :pre_rock end # Or with syntax... module Rocker def before:rock puts 'pre rock' end end class Foo include Rocker def rock puts 'We are rocking' end end Foo.new.rock # => "pre rock\nWe are rocking\n" -Jeff