On Tue, Sep 26, 2006 at 01:10:17AM +0900, 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.
> 
You can inherit.

class C2 < C1
end

Or you can make C1 a module

module C1
  def f
    p self.class
  end
end

class C2
  include C1
end