[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Get only the non-inherited methods of a class

Max Williams

11/2/2007 12:06:00 PM

Does anyone know how to get the methods of a class in such a way as to
*not* get inherited ones?

For example, the Rails class AbstractRequest has 20 or so methods, all
of which can be called with no parameters. I can call them all,
displaying the name of the method, and the result of calling it with an
empty parameter list, with


request.class.methods.each do |m|
method = request.class.method(m)
puts " #{m} = #{method.call}, "
end

This would produce

accepts = text/htmlapplication/xmlimage/pngtext/plain*/*
delete? = false
etc

However, calling the above also gets all the inherited methods as well,
many of which require parameters, and the code breaks because i'm not
supplying them.

Is there some sort of test that i can do to see if a class creates a
method, rather than inheriting it? I'm thinking of possible solutions,
like recursing up the superclass chain, and not calling the method if
any superclass responds to it, but this seems very complicated for such
a simple problem.

Any ideas, anyone?

thanks
max
--
Posted via http://www.ruby-....