Example #1
0
static VALUE
proc_arity(VALUE self)
{
    rb_proc_t *proc;
    rb_iseq_t *iseq;
    GetProcPtr(self, proc);
    iseq = proc->block.iseq;
    if (iseq) {
	if (BUILTIN_TYPE(iseq) != T_NODE) {
	    if (iseq->arg_rest < 0) {
		return INT2FIX(iseq->argc);
	    }
	    else {
		return INT2FIX(-(iseq->argc + 1 + iseq->arg_post_len));
	    }
	}
	else {
	    NODE *node = (NODE *)iseq;
	    if (nd_type(node) == NODE_IFUNC && node->nd_cfnc == bmcall) {
		/* method(:foo).to_proc.arity */
		return INT2FIX(method_arity(node->nd_tval));
	    }
	}
    }
    return INT2FIX(-1);
}
Example #2
0
static VALUE
method_arity_m(VALUE method)
{
    int n = method_arity(method);
    return INT2FIX(n);
}