From: "David A. Black" Date: 2003-12-16T22:51:28+09:00 Subject: Re: Copying methods from one class to another On Tue, 16 Dec 2003, T. Onoma wrote: > At first it seemed like it would be easy, since Ruby is so dynamic --if I add > a method to a class, every object previously defined as that class instantly > has it. But then I discoverd that the super keyword appear "prebound" to its > superclass. Take a look at: > > class C > def x > super > end > 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) > } > remove_method(m) > end > end > c = C.new > c.x > > I have satisfied the condition of the binding class being the same class type, > but nonetheless this code causes an infinite recursion on the super call. 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 David -- David A. Black dblack@wobblini.net