From: Robert Klemme Date: 2005-07-13T18:45:50+09:00 Subject: Re: Initialization via a Module Joe Van Dyk wrote: > On 7/13/05, Robert Klemme wrote: >> Joe Van Dyk wrote: >>> On 7/12/05, Daniel Brockman wrote: >>>> Call `super' from `initialize'. >>> >>> Errm.. isn't that what he's doing? >>> >>> module Foo >>> attr_reader :foo >>> def initialize >>> @foo = 'foo' >>> super >>> end >>> end >> >> Not in Bar as far as I can see. >> *That's* the place where it should be. > > I have zero understanding of this stuff, but I thought #super called > the initialize function on the class' parent. So you'd use it for > inheritance-type stuff only and not for modules. But I'm most likely > mistaken. This might help clarify: 11:40:36 [robert.klemme]: irbs >> module Mod;end => nil >> class Foo; end => nil >> class Bar Bar >> Bar.ancestors => [Bar, Mod, Foo, Object, Kernel] >> class Zap; include Mod end => Zap >> Zap.ancestors => [Zap, Mod, Object, Kernel] That's exactly the chain along which initialize super calls occur. We had a discussion a while ago about automatically generating super class in constructors under certain circumstances. I don't remember the subject thogh... Kind regards robert