Reflection to find out the names of method arguments

T

Tom Counsell

Hello

Is there a way to dynamically find out the names of a method's
arguments ?

class ABusinessObject
def doBook( person, pickup, dropoff )
end
end

businessobject.method( 'doBook' ).arity # gives 3, the number of
arguments
businessobject.method('doBook').arguments # [ 'person', 'pickup',
'dropoff' ] any ideas how to do this?

I know Rdoc does this by parsing the source code, but I'd like to do
it dynamically.

The reason? I'm messing around trying to write a 'naked objects' (
http://www.nakedobjects.org/no-approach.html#no-approach ) type thing
that uses the names of the arguments of business object methods to
guess what sort of gui to draw for the user ....

Many thanks

Tom
 
F

Florian Gross

Tom said:
Hello
Moin!

Is there a way to dynamically find out the names of a method's
arguments ?

From inside the method you could use local_variables at the very
beginning of the method.
Many thanks
Tom

Regards,
Florian Gross
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top