Skip to content

Commit

Permalink
Support symbolize_names argument to MatchData#named_captures
Browse files Browse the repository at this point in the history
  • Loading branch information
rwstauner committed Dec 13, 2024
1 parent 373a3c9 commit 0db6c47
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 @@ -40,6 +40,7 @@ Compatibility:
* Add `Dir.for_fd` (#3681, @andrykonchin).
* Add `Dir.fchdir` (#3681, @andrykonchin).
* Add `Dir#chdir` (#3681, @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 0db6c47

Please sign in to comment.