[ruby-talk:00337] Re: Arity features for Proc object?

From: matz@... (Yukihiro Matsumoto)
Date: 1999-05-24 05:41:31 UTC
List: ruby-talk #337
Hi.

In message "[ruby-talk:00336] Re: Arity features for Proc object?"
    on 99/05/24, GOTO Kentaro <gotoken@math.sci.hokudai.ac.jp> writes:

|In message "[ruby-talk:00320] Re: Arity features for Proc object?"
|    on 99/05/17, Yukihiro Matsumoto <matz@netlab.co.jp> writes:
|>I defined two methods, Proc#arity, and Method#arity, which return the
|>number of required arguments for the Proc and Method objects.  If they
|>accepts variable number of arguments, the arity return negative number.
|
|% ruby -e 'p lambda{}.arity'
|-1
|% ruby -e 'p lambda{|i|}.arity'
|-2
|
|Well, I expect 0 for the former and -1 for the latter. 

The negative number is

  -(n+1) where n is least required number of arguments

The former seems to accepts zero argument, but actually accepts
arbitrary number of arguments (for compatibility reason), so arity
returns a negative number.
                                                matz.

In This Thread