From: Sean O'Halpin Date: 2006-07-11T22:31:37+09:00 Subject: Re: module private methods inheritance ? On 7/11/06, Jonas Pfenniger wrote: > Hi list, > > while playing with ruby, I've hit a point I'm not really clear about. > > code : > > module A > def initialize; puts "From A" end > end > > module B > def initialize; puts "From B" end > end > > module A > include B > end > > class C > include A > end > > c = C.new > From A > => # > > Now, let's say that the only thing I can change in that code it the B > module. How would you do so that I get "From B" instead of "From A" ? > > -- > Cheers, > zimbatm > > http://zimbatm.oree.ch > > This might do what you want: module A def initialize puts "From A" end end module B def initialize puts "From B" end def self.included(obj) obj.class_eval { def initialize super # call this module's initialize end } end end module A include B end class C include A end c = C.new __END__ From B Regards, Sean