Method arity without instantiating an object


#1

Well,
after a grueling week of hacking through ruby source,
we are failing at this particular task.

Is there any way, given a method id and a class, to get the method’s arity?

what is known and basically understood:

  • a Method object is just a struct METHOD Data_Wrap_Struct’ed.
  • the struct’s member ‘body’ is a NODE* that is the actual doing stuff part
    of the method.
  • only the NODE* is needed to determine the arity

so we’re almost there, if it weren’t for NODE*'s. there are all the weird
macros - nd_next, nd_args, &c. - that act on the super crazy RNode (NODE)
thingy to get it to act like any number of things, as dictated by the flags.
in eval.c:mnew(), a few of these are set, but not all of the particular ones
that are used by eval.c:method_arity(), so we’re guessing that there’s
either overlap between them in their placement in the RNode structure, and
it all works out magically, or there’s some behind-the-scenes magic
happening on the NODEs sometime between mnew and method_arity.

this magic, whichever it may be, is that part that we’re unable to grok.
and maybe we’re just fuzzy-headed from working on this, but some help would
be greatly appreciated.

martin chase - stillflame at FaerieMUD dot org


(Nobuyoshi Nakada) #2

Hi,

···

At Sun, 2 Jun 2002 15:15:14 +0900, stillflame@oberon.FaerieMUD.org wrote:

after a grueling week of hacking through ruby source,
we are failing at this particular task. Is there any way, given a
method id and a class, to get the method’s arity?

Array.instance_method(:concat).arity #=> 1


Nobu Nakada