Method Reflection

I’m quite new to ruby and was amazed by the powerful reflection
mechanism, so tried to use the tracing function to analyse the object
space of our project.

It was amazingly easy to dump module,class and method definitions to xml
as they occured, but i was not able to retrieve any information about
the formal method parameters (correct term?), neither the number nor the
name. I wasn’t able to retrieve information on instance variables as
well. Is it possible ?

If this kind of information retrieval is considered useful, I would also
suggest to add in-language comments as in python (especially if the irb
gets faster and more user friendly :wink: )

ad emacs) Fixnum character literals mess up brace matching ( ?( ,?) ),
but this could be hard to fix. Is there a syntax-highlighting patch ?

Benedikt Huber wrote:

I’m quite new to ruby and was amazed by the powerful reflection
mechanism, so tried to use the tracing function to analyse the object
space of our project.

It was amazingly easy to dump module,class and method definitions to xml
as they occured, but i was not able to retrieve any information about
the formal method parameters (correct term?), neither the number nor the
name.

http://www.rubycentral.com/book/ref_c_method.html

arity gives the number of parameters (check the special cases in the doc
with method with variable number of parameters -with optional parameters-).

irb(main):001:0> a = String.new
=> “”
irb(main):002:0> a.method(‘split’).arity
=> -1
irb(main):004:0> a.method(‘insert’).arity
=> 2

i’m afraid you can’t get the name of the parameters at runtime (this is
a job for rdoc).

I wasn’t able to retrieve information on instance variables as
well. Is it possible ?

Apparently there is a instance_variables method.

emmanuel

il Mon, 2 Feb 2004 15:00:41 +0900, Benedikt Huber benjovi@gmx.net ha

but i was not able to retrieve any information about
the formal method parameters (correct term?), neither the number nor the
name. I wasn’t able to retrieve information on instance variables as
well. Is it possible ?

arity() is your friend. About names: we’ll see keyword arguments in
ruby2

If this kind of information retrieval is considered useful, I would also
suggest to add in-language comments as in python (especially if the irb
gets faster and more user friendly :wink: )

probably yuo mean docstrings. I asked this once and matz answered that
this won’t make it in ruby. But you can use the MetaTags module for
this (yes, ruby is impressively flexible :).
Or, post an RCR on rcrchive.net :slight_smile:

When Ruby supports keyword arguments, will the names of keyword method
parameters be included as part of the method selector (as done in
Smalltalk)? And will they be available at runtime to reflection?

···

“Emmanuel Touzery” emmanuel.touzery@wanadoo.fr wrote:

i’m afraid you can’t get the name of the parameters at runtime (this is
a job for rdoc).