From: Marc-Andre Lafortune Date: 2011-12-12T02:06:26+09:00 Subject: [ruby-core:41593] [ruby-trunk - Bug #5694][Open] Proc#arity doesn't take optional arguments into account. Issue #5694 has been updated by Marc-Andre Lafortune. Category set to core Status changed from Rejected to Open Changing this to "open", as this bug can not simply be "rejected" as the implementation currently doesn't agree with the documentation. Either the documentation needs to change, or the implementation needs to change. Here's why I (still) believe the implementation should change: It is strictly superior because it is consistent with Method#arity and with Proc#arity for method converted to proc. Currently: def Object.foo(a=42); end foo = Object.method(:foo).to_proc bar = ->(a=42){} foo.class == bar.class # => true foo.lambda? == bar.lambda? # => true foo.arity == bar.arity # => false It is also consistent with the current official documentation. The current behavior gives the information that a lambda/proc has a "rest" argument, but doesn't give information about any "optional" arguments, so both information would be useful. Indeed I still believe there should be a simple way to know the maximum number of parameters. I could find no intent for the current behavior in the code, no test for current behavior (test/* nor RubySpec). I think it is a clear defect as there is a contradiction with the official documentation. It currently states: "If the block has optional arguments, return -n-1, where n is the number of mandatory arguments." To be correctly reflect the current behavior, it would have to read something like "If the block has optional arguments, return -n-1, where n is the number of mandatory arguments, except that if the Proc doesn't have unlimited optional arguments (i.e. no *args, only arg=:default) and if the Proc was not created from a method, then it is considered as having no optional argument." Moreover, I'll be posting an additional issue that is a direct consequence of this same bug. ---------------------------------------- Bug #5694: Proc#arity doesn't take optional arguments into account. http://redmine.ruby-lang.org/issues/5694 Author: Marc-Andre Lafortune Status: Open Priority: Normal Assignee: Yukihiro Matsumoto Category: core Target version: ruby -v: - Currently: ->(foo = 42){}.arity # => 0, should be -1 This is contrary to the documentation and to what we should expect from the equivalent method definition. Fixed in trunk, requesting backport for the 1.9 line. -- http://redmine.ruby-lang.org