[Ruby] copying methods around

John Whitley whitley at bangpath.org
Tue Mar 20 16:18:30 PST 2007


Aaron Patterson wrote:
> I'm sure there's an easy way to do this, but I can't seem to find  
> it!  I
> want to copy a method from one class to another instance.

Does the source method have to be in a class?  Can you stuff it into  
a module on its own then just OpenStruct.include(SussudioModule) (or  
reopen OpenStruct, etc.).

I note that the presented implementation seems odd out of context, in  
that you're both returning a new instance of OpenStruct as well as  
side-affecting the OpenStruct class.

-- John




More information about the Ruby mailing list