Actions
Bug #11993
closedfoo(hash) is handled like foo(**hash)
Bug #11993: foo(hash) is handled like foo(**hash)
Description
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?
Actions