Issue #11993 has been updated by Andrew Vit.


See #11967 for Marc-Andre's explanation.

----------------------------------------
Bug #11993: foo(hash) is handled like foo(**hash)
https://bugs.ruby-lang.org/issues/11993#change-56812

* Author: Stefan Schler
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.0
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
Given this method:

    def foo(a = nil, b: nil)
      p a: a, b: b
    end

I can pass keyword arguments to it and I can turn a hash into keyword arguments with the `**` operator:

    foo(b: 1)       #=> {:a=>nil, :b=>1}
    foo(**{b: 1})   #=> {:a=>nil, :b=>1}

What baffles me is that a hash is also turned into keyword arguments *without* the `**` operator:
    
    foo({b: 1})     #=> {:a=>nil, :b=>1}

This looks like a flaw to me. I was expecting:

    foo({b: 1})     #=> {:a=>{:b=>1}, :b=>nil}

Which would have resembled the way `*` works:

    def bar(a = nil, b = nil)
      p a: a, b: b
    end

    bar(1, 2)       #=> {:a=>1, :b=>2}
    bar(*[1, 2])    #=> {:a=>1, :b=>2}
    bar([1, 2])     #=> {:a=>[1, 2], :b=>nil}

But currently, there doesn't seem to be a difference between `foo(hash)` and `foo(**hash)`.

Is this behavior intended? If so, what's the rationale behind this decision?



-- 
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>