You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow up faker-ruby/faker#2613 (comment).
Fixesrubocop#11165.
This PR fixes a false positive for `Style/RedundantEach`
when any method is used between methods containing `each` in the method name.
That method in between may convert from `Enumerator` to `Array`. e.g. `map(&:do_something)`
```ruby
'string'.each_char.class # => Enumerator
'string'.each_char.map(&:to_i).class # => Array
```
`each_with_index` is a method of `Array`, not of `Enumerator`.
```ruby
'string'.each_char.map(&:to_i).respond_to?(:each_with_index) # => true
'string'.each_char.map(&:to_i).respond_to?(:with_index) # => false
```
Therefore, it allows any method to be used between methods containing `each` to
prevent `NoMethodError`.
Follow up faker-ruby/faker#2613 (comment).
Fixes#11165.
This PR fixes a false positive for `Style/RedundantEach`
when any method is used between methods containing `each` in the method name.
That method in between may convert from `Enumerator` to `Array`. e.g. `map(&:do_something)`
```ruby
'string'.each_char.class # => Enumerator
'string'.each_char.map(&:to_i).class # => Array
```
`each_with_index` is a method of `Array`, not of `Enumerator`.
```ruby
'string'.each_char.map(&:to_i).respond_to?(:each_with_index) # => true
'string'.each_char.map(&:to_i).respond_to?(:with_index) # => false
```
Therefore, it allows any method to be used between methods containing `each` to
prevent `NoMethodError`.
Given the folliwing Ruby code
Rubocop throws an offense
and autocorrects it to
which is a false positive according to the following error:
Thank you :)
RuboCop version
The text was updated successfully, but these errors were encountered: