Project

General

Profile

Actions

Feature #17950

open

Unable to pattern-match against a String key

Added by chucke (Tiago Cardoso) about 2 months ago. Updated about 2 months ago.

Status:
Open
Priority:
Normal
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) about 2 months ago

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

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) about 2 months 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