The double splat operator **
only seems to work with hashes whose keys are symbols. It will not work when a key is a string, for example. This is true for both ways; for construction:
def foo **; end
foo(:a => 3) #=> nil
foo("a" => 3) #=> ArgumentError: wrong number of arguments (1 for 0)
and destruction:
def bar *; end
bar(**{:a => 3}) #=> nil
bar(**{"a" => 3}) #=> TypeError: wrong argument type String (expected Symbol)
Why is it limited to symbol keys?
It may be related to the fact that named keyword notation a: 3
coincides with the syntax sugar for hash with symbol keys, but as seen above, the double splat works with the ordinary hash notation :a => 3
, so I am not sure about this.