[Ruby] copying methods around
Aaron Patterson
aaron.patterson at gmail.com
Tue Mar 20 08:35:22 PST 2007
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. Here is a short
example that doesn't work, but I think illustrates what I am trying to do:
class PhilCollins
def sussudio
puts "I'm in #{self.class}"
end
def self.easy_lover
os = OpenStruct.new
alias os.sussudio :sussudio
os
end
end
f = PhilCollins.easy_lover
f.sussudio
The important line is the "alias" line. I'm trying to copy the sussudio
method to the open struct instance. I'm not sure if this has much bearing
on the solution, but the "sussudio" method is dynamically defined.
--
Aaron Patterson
http://tenderlovemaking.com/
More information about the Ruby
mailing list