Skip to content

Commit

Permalink
MatchData#named_captures: add optional symbolize_names keyword (#6952)
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan authored and eregon committed Apr 25, 2023
1 parent 4d81c20 commit 43d5579
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/matchdata/named_captures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@
it 'returns the latest matched capture, even if a later one that does not match exists' do
/\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)?\z/.match('012').named_captures.should == { 'a' => '0', 'b' => '2' }
end

ruby_version_is "3.3" do
it 'returns a Hash with Symbol keys when symbolize_names is provided a true value' do
/(?<a>.)(?<b>.)?/.match('0').named_captures(symbolize_names: true).should == { a: '0', b: nil }
/(?<a>.)(?<b>.)?/.match('0').named_captures(symbolize_names: "truly").should == { a: '0', b: nil }
end

it 'returns a Hash with String keys when symbolize_names is provided a false value' do
/(?<a>.)(?<b>.)?/.match('02').named_captures(symbolize_names: false).should == { 'a' => '0', 'b' => '2' }
/(?<a>.)(?<b>.)?/.match('02').named_captures(symbolize_names: nil).should == { 'a' => '0', 'b' => '2' }
end
end
end

0 comments on commit 43d5579

Please sign in to comment.