Bug #6086

Number of arguments and named parameters

Added by Marc-Andre Lafortune about 3 years ago. Updated over 2 years ago.

Assignee:Yukihiro Matsumoto
ruby -v:r34800 Backport:


While working on the messages of "wrong number of arguments" error (see #6085), I realized that the new named parameter feature can lead to misleading error messages:

def foo(x: 42)

arg = {x: :bar}
foo(arg) # => nil (no error)
arg = :bar
foo(arg) # => ArgumentError: wrong number of arguments (1 for 0)

It would be better if the wording was changed for methods accepting options. Maybe something like:

foo(arg) # => ArgumentError: wrong number of arguments (1 for 0 **)


Related issues

Related to Ruby trunk - Bug #6085: Treatment of Wrong Number of Arguments Closed 02/25/2012
Related to Ruby trunk - Feature #5474: keyword argument Closed 10/23/2011


#1 Updated by Koichi Sasada about 3 years ago

  • Assignee set to Yusuke Endoh

#2 Updated by Shyouhei Urabe about 3 years ago

  • Status changed from Open to Assigned

#3 Updated by Yusuke Endoh almost 3 years ago

  • Assignee changed from Yusuke Endoh to Yukihiro Matsumoto

Matz, what do you think?

I'm not against this. But I'm not sure how surprising this behavior is,
until I encounter it in actual use case.
"(1 for 0 **)" is not very good-looking, but I have no alternative idea.

Yusuke Endoh mame@tsg.ne.jp

#4 Updated by Yukihiro Matsumoto over 2 years ago

  • Status changed from Assigned to Rejected

Even though I understand the point, I am against the expression "(1 for 0 **)".
So until some one come up with better expression, we leave this as it is now.


Also available in: Atom PDF