From: Arlen Cuss Date: 2008-02-21T20:09:11+09:00 Subject: Re: Reusing the existing code. ------=_Part_2599_24753902.1203592158836 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, On Thu, Feb 21, 2008 at 10:04 PM, 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? > > Perhaps they should be modules instead? Mix-in with `include' (which makes the module's methods instance methods) or `extend' (which makes them class methods). >> module A >> def hi; puts "hi"; end >> end => nil >> module B >> def hey; puts "hey"; end >> end => nil >> class C >> include A >> extend B >> end => C >> C.new.hi hi => nil >> C.hey hey => nil >> ------=_Part_2599_24753902.1203592158836--