From: Paul Lutus Date: 2006-09-26T01:30:14+09:00 Subject: Re: How to copy a method from one class to another Sam Kong wrote: > Hi Rubyists, > > Is there a way to copy an instance method from one class to another? > > class C1 > def f > p self.class > end > end > > class C2 > end > > Now I want C2 to have f method so that I can call C2.new.f. > > Thanks. Perhaps it would be better for you to describe the problem this idea would address. If you need to have a shared method, maybe it would be better to put it in a module and associate the module with any classes needing the method. Or a parent-child relationship can be established between classes to make a particular method available to more than one class. -- Paul Lutus http://www.arachnoid.com