New issue
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
to_enum(:scan, ...) does not set Regexp.last_match #1484
Comments
Looks like an easy fix: truffleruby/src/main/ruby/core/string.rb Line 219 in c4cda96
$~ in block.binding and not the caller binding.
|
@eregon can you make a priority with this issue if the fix is easy, please? |
@deepj I'll take care of this, I forgot about it. |
@chrisseaton Please, is this possible to make a priority, please? |
Will do. |
@MaxLap FWIW, a simpler and better workaround than deep-cover/deep-cover@f3da81b (e.g., that doesn't work if the matcher matches an empty String) is: # Instead of:
source.to_enum(:scan, matcher).map { Regexp.last_match }
# This works around:
match_datas = []
source.scan(matcher) { match_datas << Regexp.last_match }
match_datas Additionally that workaround is also faster on CRuby: rubocop/rubocop#8602 The bug here is due to |
Removing this from |
One potential idea to fix this is to mark some internal methods/blocks as |
Now we've refactored how special variables are handled we can actually implement this pretty efficiently. Essentially we can do something like
This isn't quite perfect, we should ideally have a marker value so we can correctly detect when $~ and $_ have been specifically changed to |
This was resolved in 94d8eb0 using a variation of the technique I suggested above, so I will close this bug. |
A weird effect of using
to_enum
withscan
is that it will not set theRegexp.last_match
. Usingscan
alone does it just fine.In MRI and JRuby:
In truffleruby:
The text was updated successfully, but these errors were encountered: