On Wed, 28 Mar 2006, polypus wrote:

> what is the best way?

harp:~ > cat a.rb

module M
   def foo
     old_foo
   end
   def self.extend_object object
     object.class.module_eval{
       alias old_foo foo
     }
     super
   end
end

class X
   def foo
     puts X
   end
   def extend_yourself
     extend M
   end
end

class Y < X
   def foo
     puts Y
   end
end

x = X.new
y = Y.new
x.foo    #-> X
y.foo    #-> Y
x.extend_yourself
y.extend_yourself
x.foo    #-> X
y.foo    #-> Y


harp:~ > ruby a.rb
X
Y
X
Y


hth.

-a
-- 
share your knowledge.  it's a way to achieve immortality.
- h.h. the 14th dali lama