This is an ugly hack, and isn't very pretty in usage, plus it's got
lots of holes I'm sure, but:
module ParameterInspector
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def find_method_declaration(m)
cat[/def\s+#{m}($|\(.*)/]
end
def find_parameter(method_name, arity)
find_method_declaration(method_name)[/\(.*\)/][1...-1].split(',')[arity]
end
def cat
File.read(self.file)
end
end
end
Then to use it, you must write a class that defines a ::file method,
and include it.
class Example
include ParameterInspector
def self.file
__FILE__
end
def say(something)
puts something
end
end
puts Example.find_parameter :say, 0
"something"