Given this method definition:
def foo(a = nil, b: nil)
p a: a, b: b
end
When I call a method with a single hash argument, the hash is always implicitly converted to keyword arguments, regardless of **:
hash = {b: 1}
foo(hash)
foo(**hash)
I can pass another (empty) hash as a workaround:
foo(hash, {})
But , it looks rather bulky and uncomfortable.
I would expect Ruby to handle this more, how arrays are handled, i.e.:
foo(hash)
foo(**hash)
And using literals:
foo({b: 1})
foo(b: 1)
foo(**{b: 1})
The current implementation looks like a flaw, and the way I expected it to work seems obvious.
Is this a wonderful edge case? I do not think so. There is probably a good reason that it was not implemented in this way.
Can someone enlighten me please?