diff --git a/README.md b/README.md index 4664e501..91c6feec 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,10 @@ itself, JRuby and Rubinius. ## Ruby 3.3 backports +#### MatchData + +- `named_captures` (with `symbolize_keys` option) + ## Ruby 3.2 backports #### Class diff --git a/lib/backports/3.3.0/match_data.rb b/lib/backports/3.3.0/match_data.rb new file mode 100644 index 00000000..09df324d --- /dev/null +++ b/lib/backports/3.3.0/match_data.rb @@ -0,0 +1,3 @@ +require 'backports/tools/require_relative_dir' + +Backports.require_relative_dir diff --git a/lib/backports/3.3.0/match_data/named_captures.rb b/lib/backports/3.3.0/match_data/named_captures.rb new file mode 100644 index 00000000..ebc8b3eb --- /dev/null +++ b/lib/backports/3.3.0/match_data/named_captures.rb @@ -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