Thanks for the feedback. I need a way to do this without changing the met= hod
itself. I'm trying to get an external program a list of parameters from a
Ruby source file. I suppose I could write a parse script.
In that case use ParseTree like Eric suggested. Here is something that
probably does about what you want (sorry if I ruined your fun, but
this seemed like an interesting problem):
require 'enumerator'
require 'parse_tree'
class MethodParams
attr_reader
arsed, :methods
def initialize(klass)
@parsed =3D ParseTree.new.parse_tree(klass)
@methods =3D {}
@parsed[0].select {|i| i.respond_to?
[]) and i[0] =3D=3D :defn}.each d=
o |i|
if i[2][0] =3D=3D :scope
@methods[i[1]] =3D i[2][1][1][1..-1]
end
end
end
end
if $0 =3D=3D __FILE__
if ARGV.length < 1
puts "Usage: #$0 <files to analyze>"
exit(1)
end
class_list =3D ObjectSpace.enum_for
each_object, Class).to_a
ARGV.each do |file|
require file
end
new_classes =3D ObjectSpace.enum_for
each_object, Class).to_a - class_li=
st
new_classes.each do |klass|
m =3D MethodParams.new(klass)
m.methods.keys.each do |method|
puts "The parameters for #{klass}##{method} are
#{m.methods[method].join(',')}"
end
end
end
__END__
Depending on your platform, you may have trouble with RubyInline and
ParseTree. I had to do some hackery on my Windows laptop to get the
above to work. Note that the above will only show the parameters of
instance methods on classes inside the required files.
Ryan