- Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
I noticed strange behaviour - #named_captures may return capture groups and #[] returns nil instead of raising IndexError in the following scenario:
- call a scanning method with a Regexp (with named capture groups)
- call a scanning method without a Regexp pattern (
#getch,#get_byteor#scan_until/#exist?/... with a String pattern) - call
#[]with a named capture group (used in the Regexp) and#named_captures
I would expect that #[] raises IndexError and #named_captures returns nil.
Example
require 'strscan' s = StringScanner.new('Fri Dec 12 1975 14:39') s.scan(/(?<wday>Fri)/) p s.named_captures # => {"wday" => "Fri"} p s["wday"] # => "Fri" s.get_byte p s.named_captures # => {"wday" => nil} p s["wday"] # => nil s["month"] # => undefined group name reference: month (IndexError)Wondering whether it's correct behaviour.
Metadata
Metadata
Assignees
Labels
No labels