Skip to content
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

Array destructuring each triggers false match Style/HashEachMethods #12507

Closed
jcoyne opened this issue Dec 4, 2023 · 2 comments
Closed

Array destructuring each triggers false match Style/HashEachMethods #12507

jcoyne opened this issue Dec 4, 2023 · 2 comments

Comments

@jcoyne
Copy link

jcoyne commented Dec 4, 2023

In rubocop 1.58.0 this code triggers Style/HashEachMethods.

arry = [[1, 2], [3, 4]
arry.each { |_x, y| puts y }

If you correct it you get the error:

undefined method `each_value' for [[1, 2], [3, 4]]:Array (NoMethodError)

Clearly de-structuring in a block is not sufficient evidence to determine the callee is a Hash.

@koic
Copy link
Member

koic commented Dec 4, 2023

This issue is a dup with #12444.

@koic koic closed this as completed Dec 4, 2023
@koic koic added the duplicate label Dec 4, 2023
@koic
Copy link
Member

koic commented Dec 4, 2023

And, RuboCop cannot determine the type of the receiver, this cop has already been marked as unsafe:
https://docs.rubocop.org/rubocop/1.58/cops_style.html#stylehasheachmethods

Moreoverer, you can address this issue with the following configuration:

# .rubocop.yml
Style/HashEachMethods:
  AllowedReceivers: ['arry']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants