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

do not warn if using pattern matching in |a, e|, e.g |a, (digest, ids)| #463

Closed
404pnf opened this issue Sep 3, 2013 · 2 comments
Closed

Comments

@404pnf
Copy link

404pnf commented Sep 3, 2013

I take the advice of rubocop very seriously. But I tend to disagree on situation like this:

    find_duplicate_records.rb:38:3: C: Name reduce arguments |a, e| (accumulator, element).
      db.reduce([]) { |a, (_, ids)|  a << ids if ids.size > 1 ; a }
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    find_duplicate_records.rb:38:59: C: Do not use semicolons to terminate expressions.
      db.reduce([]) { |a, (_, ids)|  a << ids if ids.size > 1 ; a }

I think by using pattern matching, |a (_, ids)| is better than using |a, e| then call e[1] in the block.

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 3, 2013

Yep, we've forgotten to take this into account. On a somewhat unrelated note - in your particular case you'll be better served by each_with_object.

@404pnf
Copy link
Author

404pnf commented Sep 4, 2013

Thank you! I love each_with_object, that's the correct way.

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

2 participants