We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I noticed strange behaviour - #named_captures may return capture groups and #[] returns nil instead of raising IndexError in the following scenario:
#named_captures
#[]
nil
IndexError
#getch
#get_byte
#scan_until
#exist?
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.
The text was updated successfully, but these errors were encountered:
Good catch!
We should clear named captures.
Sorry, something went wrong.
@naitoh Do you want to work on this too?
Do you want to work on this too?
Yes, I would like to try this issue, too.
Fix a bug that scanning methods that don't use Regexp don't clear nam…
1b3de41
…ed capture groups Fix rubyGH-135
Successfully merging a pull request may close this issue.
I noticed strange behaviour -
#named_captures
may return capture groups and#[]
returnsnil
instead of raisingIndexError
in the following scenario:#getch
,#get_byte
or#scan_until
/#exist?
/... with a String pattern)#[]
with a named capture group (used in the Regexp) and#named_captures
I would expect that
#[]
raisesIndexError
and#named_captures
returnsnil
.Example
Wondering whether it's correct behaviour.
The text was updated successfully, but these errors were encountered: