From: "T. Onoma" Date: 2003-12-16T23:46:55+09:00 Subject: Re: Copying methods from one class to another On Tuesday 16 December 2003 02:51 pm, David A. Black wrote: > When I ran it I got: > > redef.rb:7: warning: already initialized constant C > redef.rb:3:in `x': super: no superclass method `x' (NoMethodError) > from redef.rb:19 > Thanks David, I forgot the most important part! Here, this one makes it even more plain: class C # don't even need the def here end class C < C; @__aspect__ = true def self.method_added(m) meth = self.instance_method(m) self.superclass.class_eval %Q{ remove_method(:#{m}) if method_defined?(:m) define_method(:#{m}, meth) } self.remove_method(m) end end class C # this is what I forgot: to add a method def x print "<"; super end end c = C.new c.x -- T.