From: Gennady Date: 2003-03-11T01:26:58+09:00 Subject: Re: Limited Support for Multiple Inheritance in SWIG/Ruby How about this: For every C++ class (Base1, Base2, Base3) we create a pair of Ruby objects: module Base1_internals # Here come all instance methods of Base1 end class Base1 include Base1_internals # Other Base1 stuff end # Same for Base2 # Same for Base3 Then for Derrived we may have: module Derrived_internals # Here come all instance methods of Derrived end class Derrived include Derrived_internals include Base1_internals include Base2_internals include Base3_internals # Other Derrived stuff end Hope this helps, Gennady. ----- Original Message ----- From: To: "ruby-talk ML" ; Cc: Sent: Monday, March 10, 2003 7:41 AM Subject: Limited Support for Multiple Inheritance in SWIG/Ruby > All, > > We'd like to be able to provide support for a kind of "limited" multiple > inheritance in SWIG's Ruby module. It is limited in the sense that, since > Ruby doesn't support MI, we'll obviously never have the case that class "D" > is a direct subclass of more than one base class. However, it might be > useful to provide support for this kind of C++ class structure: > > class Base1 { > public: > void base1(); > }; > > class Base2 { > public: > void base2(); > }; > > class Base3 { > public: > void base3(); > }; > > class Derived : public Base1, public Base2, public Base3 { > public: > }; > > With the limited MI I'm thinking about, all three C++ classes would get > wrapped by SWIG as Ruby classes, with "Derived" being a subclass of "Base1" > only. The bonus, however, would be that you'd also be able to call any of > the methods declared for "Base2" or "Base3" (and their ancestors) on an > instance of "Derived". > > The simplest solution so far seems to be to override Derived's > #method_missing method, something like this (pseudocode): > > class Derived > def method_missing(mth, *args) > for each base other than Base1 > see if this base can handle it > end > super # call Object#method_missing > end > end > > but I haven't tried to implement this yet. > > Can someone else point out the flaws in this, and/or suggest other > possibilities? > > Thanks in advance, > > Lyle > >