Project

General

Profile

Actions

Bug #16371

closed

Inconsistent usage of Double splat operator

Added by dmytro.vasin (Dmytro Vasin) over 4 years ago. Updated about 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.6.0
[ruby-core:95951]

Description

Here is an issue with a weird behavior of ruby double splat operator:

a = {a: 'a'}
b = {'b' => 'b'}

{x: 'x', **a}
#=> {:x=>"x", :a=>"a"}

{x: 'x', **b}
#=> TypeError (hash key "b" is not a Symbol)

When I do that implicitly, it works:

{x: 'x', **{'b' => 'b'}} 
#=> {:x=>"x", "b"=>"b"}

At the same time:

{**{'b' => 'b'}}
# TypeError (hash key "b" is not a Symbol)

From my point of view, it definitely works inconsistently.

Could you help with this example or give an advice? (maybe I used it incorrectly?)

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0