Skip to content

Commit

Permalink
[GR-59866] Support symbolize_names argument to `MatchData#named_cap…
Browse files Browse the repository at this point in the history
…tures`

PullRequest: truffleruby/4426
  • Loading branch information
andrykonchin committed Dec 17, 2024
2 parents 08fdec7 + 0db6c47 commit 2c1e91b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Compatibility:
* Add `Dir.fchdir` (#3681, @andrykonchin).
* Add `Dir#chdir` (#3681, @andrykonchin).
* Declare `File::SHARE_DELETE` constant (#3745, @andrykonchin).
* Support `symbolize_names` argument to `MatchData#named_captures` (#3681, @rwstauner).

Performance:

Expand Down
2 changes: 0 additions & 2 deletions spec/tags/core/matchdata/named_captures_tags.txt

This file was deleted.

4 changes: 3 additions & 1 deletion src/main/ruby/truffleruby/core/match_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def names
regexp.names
end

def named_captures
def named_captures(symbolize_names: false)
names = Primitive.regexp_names(self.regexp).map(&:first)
names.map!(&:to_s) unless symbolize_names
names.collect { |name| [name, self[name]] }.to_h
end

Expand Down

0 comments on commit 2c1e91b

Please sign in to comment.