From: Ron Fox Date: 2008-02-22T19:45:05+09:00 Subject: Re: Reusing the existing code. That's >not< a beginner posting at all ;-) There's a well known maxim in OO programming to prefer composition (what you are suggesting) to inheritance. The Suggestion by prizrak6 can also be used by inheriting from one class and mixing in the second bits of functionality as a module. The thing to always ask yourself is what the relationship between the new class and the existing classes is. New class is an old class -> inheritance New class has an old class -> composition Inheritance is very useful but often overused...where composition is much more appropriate. Without knowing more about the actual problem MohsinHijazee has, it's not possible to make detailed recommendations. Ron Fox Senior Physicist National Superconducting Cyclotron Lab Michigan State University East Lansing, MI 48824-1321 Morel wrote: > wrote: > >> On 21 ???, 13:02, MohsinHijazee wrote: >>> Hi! >>> I have a new class which needs to reuse the code in two classes. >>> But I can only derive it from one class. How should I go about it then? >> Use mixins, by defining modules > > Posting as a beginner, I wonder if something like this (inheriting from > one class while incorporating an instance of the other) might work: > > class SiblingClass < ParentClass1 > > def initialize > @reuseParent2 = ParentClass2.new() > end > > def method_missing(methodName,*args) > @reuseParent2.send(methodName,*args) > end > > end > >