Project

General

Profile

Actions

Bug #20251

closed

Wrong ArgumentError raised for hash as last parameter before keyword aguments

Added by phillipp (Phillipp Röll) over 1 year ago. Updated over 1 year ago.

Status:
Feedback
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]
[ruby-core:116650]

Description

Suppose we have the following method as part of an API client:

def post(path, params, timeout: 30)
end

The method is then called like this:

post("/persons", name: "John Doe")

This leads to an error message ArgumentError: wrong number of arguments (given 1, expected 2). I suppose the (implicit) hash is used for keyword arguments.

My expectation would be, that:

  1. the Hash (passed without the brackets, but that is not needed in other cases) would be accepted as the params argument or
  2. that an ArgumentError would be raised with the message ArgumentError: unknown keyword: :name

In my opinion, the first case should be what's happening, the second behaviour would be my expectation if that's not possible, because a hash without brackets can't be mixed without passing keyword arguments.

Either way, starting with Ruby 3.0, the behaviour makes no sense to me anymore.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0