From: Johan Nilsson Date: 2004-12-09T21:17:31+09:00 Subject: Inheritance, mixins and initializers Hi, I've got a question regarding inheritance, mixins, order of initialization and calling module/super class "initializers". I'd like to do something along the lines of (pseudo-ruby code): --- class Base def initialize(field_count) @fields = Array.new(field_count) end end module FooMixin def initialize(foo_field) @foo_field = foo_field self.fields[@foo_field] = Foo.new end def foo self.fields[@foo_field] end end module BarMixin def initialize(bar_field) @bar_field = bar_field self.fields[@bar_field] = Bar.new end def bar self.fields[@bar_field] end end class Derived < Base include FooMixin include BarMixin def initialize super(2) FooMixin(0) BarMixin(1) end end --- Obviously this doesn't work - is there any way of achieving something similar? The Foo/Bar mixins depend on Base being initialized before them (ok, maybe not in this particular example). // Johan