Issue #10856 has been updated by Tymon Tobolski.


Hi Matz,

I think I just found a real-world use-case for exactly this issue - please take a look at the (simplified) example below.

~~~ruby
class Dispatcher
  def call(event, args)
    public_send(event, **args)
  end

  def first_event(myarg:)
    # ...
  end

  def second_event
    # ...
  end
end
~~~

And the call site looks like this:

~~~ruby
disp = Dispatcher.new
disp.call(params[:event], params[:args])
~~~


Then we can observe:

~~~ruby
disp.call(:first_event, {myarg: 123}) # => passes correctly, all good               

disp.call(:first_event, {})                         # => missing keyword: myarg - exactly what I'd expect
disp.call(:first_event, {myarg: 123, other: "foo"}) # => unknown keyword: other - exactly what I'd expect      

disp.call(:second_event, {})          # => wrong number of arguments (1 for 0) - this /should/ just pass without error
~~~

So, in case the `params[:args]` is empty we would expect to either get a "missing keyword" exception or simply valid method execution when such param is not required. 

Please let me know what do you think about it.

----------------------------------------
Bug #10856: Splat with empty keyword args gives unexpected results
https://bugs.ruby-lang.org/issues/10856#change-53720

* Author: Sean Griffin
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
When keyword args are passed to a method with splat, and there are no keyword args, an empty hash is sent. I would expect no argument to be given, same as splat with an empty array. For example:

    def foo
    end

    foo(**{})

This causes an argument error, as an empty hash is passed. I would expect the same behavior as

    def foo
    end

    foo(*[])



-- 
https://bugs.ruby-lang.org/