[DOCBUG] Proc#arity

J

Joel VanderWerf

An inconsistency in the docs for Proc#arity ? Here's what ri says:

arguments. A +proc+ with no argument declarations returns -1, as it
can accept (and ignore) an arbitrary number of parameters.

Proc.new {}.arity #=> 0

$ ruby -v
ruby 1.9.0 (2004-11-08) [i686-linux]
 
M

Mauricio Fernández

An inconsistency in the docs for Proc#arity ? Here's what ri says:

arguments. A +proc+ with no argument declarations returns -1, as it
can accept (and ignore) an arbitrary number of parameters.

Proc.new {}.arity #=> 0

$ ruby -v
ruby 1.9.0 (2004-11-08) [i686-linux]


Thu Mar 18 16:22:38 2004 Yukihiro Matsumoto <[email protected]>
[...]

* eval.c (proc_arity): arity is now defined as number of
parameters that would not be ignored. i.e. Proc.new{}.arity
returns zero. update test suites too.


http://rcrchive.net/rcr/show/227
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: [DOCBUG] Proc#arity"

|> An inconsistency in the docs for Proc#arity ? Here's what ri says:
|>
|> arguments. A +proc+ with no argument declarations returns -1, as it
|> can accept (and ignore) an arbitrary number of parameters.

| * eval.c (proc_arity): arity is now defined as number of
| parameters that would not be ignored. i.e. Proc.new{}.arity
| returns zero. update test suites too.

And lambda{}.call(1) should have made to raise exception. I will fix
this. Could somebody update the document?

matz.
 
S

Sam Roberts

Quoteing (e-mail address removed), on Sun, Nov 14, 2004 at 06:43:32PM +0900:
In message "Re: [DOCBUG] Proc#arity"
|> An inconsistency in the docs for Proc#arity ? Here's what ri says:
|>
|> arguments. A +proc+ with no argument declarations returns -1, as it
|> can accept (and ignore) an arbitrary number of parameters.

| * eval.c (proc_arity): arity is now defined as number of
| parameters that would not be ignored. i.e. Proc.new{}.arity
| returns zero. update test suites too.

And lambda{}.call(1) should have made to raise exception. I will fix
this. Could somebody update the document?

If I understand this correctly, the docs should now say something like
the below?

Cheers,
Sam


Index: eval.c
===================================================================
RCS file: /src/ruby/eval.c,v
retrieving revision 1.616.2.68
diff -u -r1.616.2.68 eval.c
--- eval.c 12 Nov 2004 06:06:12 -0000 1.616.2.68
+++ eval.c 14 Nov 2004 16:26:35 -0000
@@ -8207,15 +8207,14 @@
* call-seq:
* prc.arity -> fixnum
*
- * Returns the number of arguments required by the block. If the block
+ * Returns the number of arguments that would not be ignored. If the block
* is declared to take no arguments, returns 0. If the block is known
* to take exactly n arguments, returns n. If the block has optional
* arguments, return -n-1, where n is the number of mandatory
- * arguments. A <code>proc</code> with no argument declarations
- * returns -1, as it can accept (and ignore) an arbitrary number of
- * parameters.
+ * arguments. A <code>proc</code> with no argument declarations
+ * is handled like a block declaring <code>||</code> as its arguments.
*
- * Proc.new {}.arity #=> -1
+ * Proc.new {}.arity #=> 0
* Proc.new {||}.arity #=> 0
* Proc.new {|a|}.arity #=> 1
* Proc.new {|a,b|}.arity #=> 2
 
D

Dave Thomas

And lambda{}.call(1) should have made to raise exception. I will fix
this. Could somebody update the document?

Matz:

The document is simply the comment before the method- :)


Cheers

Dave
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: [DOCBUG] Proc#arity"

|> Could somebody update the document?
|
|Matz:
|
|The document is simply the comment before the method- :)

I know. I was just too lazy to make up "proper" statement.

matz.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: [DOCBUG] Proc#arity"

|If I understand this correctly, the docs should now say something like
|the below?

Thank you!

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Arity? 2
behavior of proc { || } on 1.9 2
Proc#== behaviour (from Ruby-Core) 6
Proc vs lambda vs proc 19
ANN main-4.4.0 0
[ANN] main-3.0.1 0
oddity with block argument passing 3
[ANN] JRuby 1.1 RC 1 Released 20

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top