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

Cop enforcing using map for search instead of arrays #356

Open
dmitrytrager opened this issue May 6, 2023 · 0 comments
Open

Cop enforcing using map for search instead of arrays #356

dmitrytrager opened this issue May 6, 2023 · 0 comments

Comments

@dmitrytrager
Copy link

If we need to look for value, map is usually better option than array.

I often see something like this:

values = <collect into array>
collection.each do |item|
  values.select { |v| v['attr'] = item.some_method }
end

It could be more performant to have this instead:

values = <collect into map>
collection.each do |item|
  values[item.some_method]
end

Maybe a new cop could help here.
Since map is not always the right choice, some enforcing style options could be useful too.

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

No branches or pull requests

1 participant