Actions
Bug #21184
closedSyntaxError when combining `in` with inline hash-rocket (`=>`)
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [x86_64-linux]
Description
I believe the following should be valid syntax but it's throwing a SyntaxError
:
{ a: 1 } in { a: 1 } # => true
{ a: 1 } in { a: Integer } # => true
pattern = { "a" => 1 }; { "a" => 1 } in pattern # => true
{ "a" => 1 } in { "a" => 1 } # => SYNTAX ERROR
Updated by alanwu (Alan Wu) 15 days ago
- Status changed from Open to Rejected
It's working as documented
Note that only symbol keys are supported for hash patterns.
By the way, the third line that uses in
uses a wildcard pattern so is essentially assigning to pattern
:
irb(main):003> pattern = { "a" => 1 }; 0 in pattern
=> true
irb(main):004> p pattern
0
Updated by jtannas (Joel Tannas) 15 days ago
Thank you for the prompt reply Alan.
Sorry I missed that line while skimming through that document prior to submitting.
I think I need to do some more reading up on the =>
operator.
Actions
Like0
Like0Like0