[ruby-core:95408] [Ruby master Bug#14176] Unclear error message when calling method with keyword arguments
From:
merch-redmine@...
Date:
2019-10-17 23:44:07 UTC
List:
ruby-core #95408
Issue #14176 has been updated by jeremyevans0 (Jeremy Evans).
Status changed from Open to Closed
With the separation of keyword arguments and positional arguments in #14183, I think this can be closed.
----------------------------------------
Bug #14176: Unclear error message when calling method with keyword arguments
https://bugs.ruby-lang.org/issues/14176#change-82151
* Author: vfonic (Viktor Fonic)
* Status: Closed
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin17]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
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!
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>