Project

General

Profile

Actions

Feature #19591

closed

Add symbolize_names to MatchData#named_captures

Added by palkan (Vladimir Dementyev) about 1 year ago. Updated about 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:113191]

Description

This feature is a follow-up for MatchData#deconstruct_keys (see https://github.com/ruby/ruby/pull/6216).

Example:

m = /(?<a>.)(?<a>.)/.match("01")  # => #<MatchData "01" a:"0" a:"1">
m.named_captures #=> {"a" => "1"}
m.named_captures(symbolize_names: true) #=> {:a => "1"}

The underlying (C) functionality has been already implemented. The proposal is to expose it via the optional symbolize_keys: true | false keyword argument.

PR is attached: https://github.com/ruby/ruby/pull/6952

Actions

Also available in: Atom PDF

Like0
Like0Like1Like0Like0Like0Like0