From: Jamis Buck Date: 2003-12-13T11:28:38+09:00 Subject: Re: Q: introspection Mike Hall wrote: >Is there a way to find out the methods that a given class/modules provides, >without including the methods from Object, Kernel, etc, and without deleting >any commonly named methods? > >For example, the Dir class, (Dir.methods - Object.methods) will remove the 'new' >method, and the 'open' method gets tossed if we subract out the Kernel.methods. > >Is this possible with the current set of 'public_methods' and 'private_methods' et.al? > >Thanks! > > I'd be interested in this, too. I typically do ( MyClass.instance_methods - MyClass.superclass.instance_methods ), but this throws out any that MyClass redefines, which is bad. To get around this I've been forced to parse the inspection string of UnboundMethod: methods = MyClass.instance_methods.find_all do |name| MyClass.instance_method( name ).inspect =~ /MyClass#/ end As for not deleting any "commonly named" methods... I guess I'm not sure what you mean there. I guess you could define an array of method names that you don't want deleted, and add them to the loop. But the system itself has no way of knowing that you WANT the 'open' method of Dir (for instance) unless you specify some kind of search criteria that include it. BTW, a method of Method and UnboundMethod that tells you the name of the class that most recently defined the method would be very handy. Is there one, and I just haven't seen it? -- Jamis Buck jgb3@email.byu.edu ruby -h | ruby -e 'a=[];readlines.join.scan(/-(.)\[e|Kk(\S*)|le.l(..)e|#!(\S*)/) {|r| a << r.compact.first };puts "\n>#{a.join(%q/ /)}<\n\n"'