Skip to content

Commit

Permalink
Add MatchData#named_captures with symbolize_keys option
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Jan 3, 2024
1 parent a0eaa71 commit d2217b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ itself, JRuby and Rubinius.

## Ruby 3.3 backports

#### MatchData

- `named_captures` (with `symbolize_keys` option)

## Ruby 3.2 backports

#### Class
Expand Down
3 changes: 3 additions & 0 deletions lib/backports/3.3.0/match_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'backports/tools/require_relative_dir'

Backports.require_relative_dir
12 changes: 12 additions & 0 deletions lib/backports/3.3.0/match_data/named_captures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if MatchData.instance_method(:named_captures).arity == 0
require 'backports/tools/alias_method_chain'

class MatchData
def named_captures_with_symbolize_option(symbolize_keys: false)
captures = named_captures_with_symbolize_option
captures.transform_keys!(&:to_sym) if symbolize_keys
captures
end
Backports.alias_method_chain self, :named_captures, :symbolize_option
end
end

0 comments on commit d2217b1

Please sign in to comment.