Project

General

Profile

Actions

Feature #17950

open

Unable to pattern-match against a String key

Added by chucke (Tiago Cardoso) over 3 years ago. Updated over 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:104246]

Description

I'm unable to parse against an internal hash, when the internal hash contains strings as keys:

case {status: 200, headers: {"content-type" => "application/json"}, body: "bla"}
in { status: , headers: {"content-type" => type}, body: }
# syntax error, unexpected terminator, expecting literal content or tSTRING_DBEG or tSTRING_DVAR or tLABEL_END
# ...tus: , headers: {"content-type" => type}, body: }

however, this works:

h = {"content-type" => "application/json"}
case {status: 200, headers: {"content-type" => "application/json"}, body: "bla"}
in { status: , headers: ^h, body: }

Updated by jeremyevans0 (Jeremy Evans) over 3 years ago

  • Tracker changed from Bug to Feature
  • ruby -v deleted (3.0.1)
  • Backport deleted (2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN)

The fact that only symbol keys are supported is documented (https://docs.ruby-lang.org/en/master/doc/syntax/pattern_matching_rdoc.html#label-Patterns), so this is expected and not a bug. Switching to feature request.

Updated by chucke (Tiago Cardoso) over 3 years ago

Switching to feature request.

Makes sense. Hopefully the example of matching HTTP headers makes it a compelling case for such.

Actions

Also available in: Atom PDF

Like0
Like0Like0