Project

General

Profile

Actions

Bug #14176

closed

Unclear error message when calling method with keyword arguments

Added by vfonic (Viktor Fonic) almost 7 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin17]
[ruby-core:84240]

Description

I (wrongly) created a method with the following signature:

def asd(first, options: {}); end

(notice that options is a keyword argument)

I called the method this way:

asd(arg, options)

And got the following misleading error:
ArgumentError: wrong number of arguments (given 2, expected 1)

It took me some time to realize that the options argument is a keyword argument:

method(:asd)
Object#asd(first, ?)

It would be much more helpful if the error would mention this:
ArgumentError: wrong number of arguments (given 2, expected 1 and 1 keyword argument: options)

Thanks!


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #13196: Improve keyword argument errors when non-keyword arguments givenClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0