Actions
Bug #21288
closedStringScanner#named_captures overrides matched captures with unmatched captures
Description
StringScanner#named_captures operates inconsistently with MatchData#named_captures when there is the same name used in multiple branches
For Regexp it uses the value that was captured (useful). For StringScanner it uses the one last in source order.
require 'strscan'
re = /(?<test>value)|(?<test>other branch)/
scanner = StringScanner.new("value")
scanner.scan(re)
scanner.named_captures #=> {"test" => nil}
"value".match(re).named_captures # => {"test" => "value"}
scanner = StringScanner.new('other branch')
scanner.scan(re)
scanner.named_captures #=> {"test" => "other branch"}
"other branch".match(re).named_captures # => {"test" => "other branch"}
Actions
Like0
Like0Like0Like0Like0Like0