Proc#arity bug?


#1

p = proc {}
p.arity -> -1

shouldn’t that be returning 0?

btw p = proc { |*a| } gives me -1 like it should.

ruby 1.8.4 (2005-12-24) [i686-linux]


#2

On Sun, May 07, 2006 at 01:11:44PM +0900, Logan C. wrote:

It’s not a bug it’s a feature:

proc { || } has arity 0, proc {} takes any number of args and ignores
them.

Note that lambda{}.arity == 0 in 1.9:

RUBY_VERSION # => “1.9.0”
RUBY_RELEASE_DATE # => “2006-05-01”
lambda{ }.arity # => 0
lambda{}.call(1,2,3)

~> -:4: wrong number of arguments (3 for 0) (ArgumentError)

~> from -:4


#3

On May 6, 2006, at 11:03 PM, polypus wrote:


Posted via http://www.ruby-forum.com/.

It’s not a bug it’s a feature:

proc { || } has arity 0, proc {} takes any number of args and ignores
them.


#4

“M” == Mauricio F. removed_email_address@domain.invalid writes:

M> lambda{ }.arity # => 0
M> lambda{}.call(1,2,3)
M> # ~> -:4: wrong number of arguments (3 for 0) (ArgumentError)
M> # ~> from -:4

moulon% ruby -ve ‘p proc{}.arity; p proc{}.call(1,2,3)’
ruby 1.9.0 (2006-05-01) [i686-linux]
0
nil
moulon%

Guy Decoux


#5

Hi,

In message “Re: Proc#arity bug?”
on Sun, 7 May 2006 18:04:16 +0900, ts removed_email_address@domain.invalid
writes:

|moulon% ruby -ve ‘p proc{}.arity; p proc{}.call(1,2,3)’
|ruby 1.9.0 (2006-05-01) [i686-linux]
|0
|nil

Hmm, indeed it’s inconsistent. I will fix, either arity to return -1,
or call to raise ArgumentError.

						matz.