In Ruby 1.9.2, you can trivially get the parameter list of any Proc
(and thus of course also of any Method
or UnboundMethod
) with Proc#parameters
:
def foo(a, b=nil, *c, d, &e); end
p method(:foo).parameters
# => [[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]]
The format is an array of pairs of symbols: type (required, optional, rest, block) and name.
For the format you want, try
method(:foo).parameters.map(&:last).map(&:to_s)
# => ['a', 'b', 'c', 'd', 'e']