Robert Klemme
7/13/2005 9:44:00 AM
Joe Van Dyk wrote:
> On 7/13/05, Robert Klemme <bob.news@gmx.net> wrote:
>> Joe Van Dyk wrote:
>>> On 7/12/05, Daniel Brockman <daniel@brockman.se> 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<Foo;include Mod; end
=> 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