Hi Joe,

Joe Van Dyk <joevandyk / gmail.com> writes:

> I have zero understanding of this stuff, but I thought #super called
> the initialize function on the class' parent.

That's right.

> So you'd use it for inheritance-type stuff only and not for modules.

But modules are inheritance-type stuff.  You should think of modules
as uninstantiable classes, and `mixin' as a warm and fuzzy euphemism
for multiple inheritance.  Then it will all start to make sense.

(There are people who feel that truly unifying modules and classes to
just one essential concept would reduce this kind of confusion.)

> But I'm most likely mistaken.

I don't think you realize that when you include a module `Foo' into a
module or class `Bar', then `Foo' becomes the parent of `Bar'.

The following example should illustrate this nicely:

   module Foo
     def initialize
       puts "Foo#initialize not calling super"
     end
   end

   class Bar
     def initialize
       puts "Bar#initialize is the topmost initializer"
     end
   end

   class Baz < Bar
     def initialize
       puts "Baz#initialize calling super..."
       super
     end
   end

   Baz.ancestors   #=> [Baz, Bar, Object, Kernel]
   Baz.superclass  #=> Bar

   Baz.new
   # Baz#initialize calling super...
   # Bar#initialize is the topmost initializer

   class Baz
     include Foo
   end

   Baz.ancestors   #=> [Baz, Foo, Bar, Object, Kernel]
   Baz.superclass  #=> Bar

   Baz.new
   # Baz#initialize calling super...
   # Foo#initialize not calling super

Note in particular how failing to call `super' from an `initialize'
method in a module prevents the rest of the initializers from running.

That's because modules are really just emasculated classes, and method
calls work just the same across modules and classes.

-- 
Daniel Brockman <daniel / brockman.se>

    So really, we all have to ask ourselves:
    Am I waiting for RMS to do this?   --TTN.