Skip to content

Commit 2c1e91b

Browse files
committed
[GR-59866] Support symbolize_names argument to MatchData#named_captures
PullRequest: truffleruby/4426
2 parents 08fdec7 + 0db6c47 commit 2c1e91b

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Compatibility:
4141
* Add `Dir.fchdir` (#3681, @andrykonchin).
4242
* Add `Dir#chdir` (#3681, @andrykonchin).
4343
* Declare `File::SHARE_DELETE` constant (#3745, @andrykonchin).
44+
* Support `symbolize_names` argument to `MatchData#named_captures` (#3681, @rwstauner).
4445

4546
Performance:
4647

spec/tags/core/matchdata/named_captures_tags.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/main/ruby/truffleruby/core/match_data.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def names
9191
regexp.names
9292
end
9393

94-
def named_captures
94+
def named_captures(symbolize_names: false)
95+
names = Primitive.regexp_names(self.regexp).map(&:first)
96+
names.map!(&:to_s) unless symbolize_names
9597
names.collect { |name| [name, self[name]] }.to_h
9698
end
9799

0 commit comments

Comments
 (0)