Project

General

Profile

Bug #21288

Updated by robotdana (Dana Sherson) 5 days ago

StringScanner#named_captures operates inconsistently with MatchData#named_captures Regexp#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. 

 ```ruby 
 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"} 
 ```

Back