Forum: Ruby Proc#arity bug?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
10e3653e8f411fa2d140129b947cdaea?d=identicon&s=25 polypus (Guest)
on 2006-05-07 05:03
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]
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-05-07 06:12
(Received via mailing list)
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.
Dd76a12d66f843de5c5f8782668e7127?d=identicon&s=25 Mauricio Fernandez (Guest)
on 2006-05-07 09:38
(Received via mailing list)
On Sun, May 07, 2006 at 01:11:44PM +0900, Logan Capaldo 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
956f185be9eac1760a2a54e287c4c844?d=identicon&s=25 ts (Guest)
on 2006-05-07 11:05
(Received via mailing list)
>>>>> "M" == Mauricio Fernandez <mfp@acm.org> 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
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2006-05-07 16:19
(Received via mailing list)
Hi,

In message "Re: Proc#arity bug?"
    on Sun, 7 May 2006 18:04:16 +0900, ts <decoux@moulon.inra.fr>
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.
This topic is locked and can not be replied to.