and later, if I have the function name in a string, is there a way to
get the parameter names using reflection in Ruby? Something similar
to the following PHP snippet,
$a = new ReflectionFunction("function_name");
$a->getParameters();
There is not; as Bernardo said, Ruby only allows you to check the
arity of the method.
I had a need for this, too. (I was working on a project that allowed
developers to provide arbitrary Ruby-based plugins, and the GUI of the
application needed to expose the methods and their paramters
visually.)
and later, if I have the function name in a string, is there a way to
get the parameter names using reflection in Ruby? Something similar
to the following PHP snippet,
$a = new ReflectionFunction("function_name");
$a->getParameters();
Forgive the naive thoughts of a ruby ruby, but what if you accepted an
array as the parameter? You could use any number of elements and you
would always know which is which.
and later, if I have the function name in a string, is there a way to
get the parameter names using reflection in Ruby? Something similar
to the following PHP snippet,
$a = new ReflectionFunction("function_name");
$a->getParameters();
Forgive the naive thoughts of a ruby ruby, but what if you accepted an
array as the parameter? You could use any number of elements and you
would always know which is which.
-- Posted via http://www.ruby-forum.com/\.
You can accomplish this with the Ruby2Ruby gem. Here is a pastie of some code that can do this for you: