diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c6226975a25..f92f9ae6d48c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/spec/tags/core/matchdata/named_captures_tags.txt b/spec/tags/core/matchdata/named_captures_tags.txt deleted file mode 100644 index 3a59edb70403..000000000000 --- a/spec/tags/core/matchdata/named_captures_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:MatchData#named_captures returns a Hash with Symbol keys when symbolize_names is provided a true value -fails:MatchData#named_captures returns a Hash with String keys when symbolize_names is provided a false value diff --git a/src/main/ruby/truffleruby/core/match_data.rb b/src/main/ruby/truffleruby/core/match_data.rb index d36c184c019c..6637e84d3732 100644 --- a/src/main/ruby/truffleruby/core/match_data.rb +++ b/src/main/ruby/truffleruby/core/match_data.rb @@ -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