From: Jean-Hugues ROBERT Date: 2004-05-01T01:12:11+09:00 Subject: Re: coerce(), what protocol to implement it At 17:54 30/04/2004 +0900, you wrote: >il Fri, 30 Apr 2004 14:04:38 +0900, Jean-Hugues ROBERT > ha scritto:: > > >Is there something like > > Class.implementers( meth) > >that would return a list of all known classes that implement > >some method ? > >this? > > ObjectSpace.each_object(Class){|x| p x if >x.instance_methods.member?'coerce'} I haven't played with ObjectSpace yet. Now I can see that it is an interesting thing ! Thanks. What I need is almost what you propose. The difference is that I need to know what classes do actually implement some method, versus inherit an existing implementation. i.e. class X; def meth() end end class Y < X; end Class.implementers( :meth) # => X does implement :meth, Y merely inherit it. It is easy to assert that X actually implements :meth, because X.superclass does not. However I still don't know how to filter out Y. Next step will be to figure out "where" X defines :meth. A refactoring editor could use that to point to :meth implementations that may need some refactoring. Or, regarding my initial need, I could know which file to look at where :coerce is defined (so that I can understand how it works, which is something I don't need to do anymore, thanks to all the gentle answers to my initial question). Yours, Jean-Hugues ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17