From: ES Date: 2005-10-07T02:42:28+09:00 Subject: Re: techniques for module to contribute to initialize() of its including classes Robert Klemme wrote: > itsme213 wrote: > >>What are good design techniques for this e.g. if the module adds some >>instance variables to its included class? >> >>module M >> def f >> @f >> end >> # how to initialize @f ? >>end >> >>class A >> include M >>end >>Thanks. > > > Do it like this and the module initialite will seamlessly integrate into > the class inheritance chain: > > module M > def initialize(*a,&b) > super > @f = 10 > end > end This does not work directly if the class itself defines an #initialize as it will take precedence over the module version. > There have been discussions about this > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/121611 > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/129974 > > Kind regards > > robert E