Closed pocke closed 4 years ago
@pocke Great, thank you for the contribution! I will release a new version with your fix later today.
I also think the cop is a good idea.
Perhaps mixing both types should even cause a warning in Onigmo because the results are really counter-intuitive:
/(a)(?<name>b)/ =~ 'ab'; $1 # => 'b'
Thanks for merging and the advice!
Perhaps mixing both types should even cause a warning in Onigmo because the results are really counter-intuitive:
Good idea! I'll open an issue to Onigmo.
@pocke v1.7.0 is now released with your fix.
Problem
Currently,
Subexpression#traverse
andSubexpression#each_expression
require a block. So It is difficult to combine other Enumerator methods, such asmap
,select
and so on.And, in the real world, I'd like to use it for RuboCop. https://github.com/pocke/rubocop-regular_expression/blob/b3f243b01973705cf43e8a3594c0854729e1ab7d/lib/rubocop/cop/regular_expression/mixed_capture_types.rb#L31-L41
Solution
Make them accept calling without a block.
Note
I found a bug of
MatchLength#each
method. It wasn't aware ofopts
argument if the method is called without a block. So this pull request also fixes the problem.