Skip to content

Extract helper module to detect repeated nodes#2155

Open
Darhazer wants to merge 1 commit intomasterfrom
extract-module-for-repeated-nodes
Open

Extract helper module to detect repeated nodes#2155
Darhazer wants to merge 1 commit intomasterfrom
extract-module-for-repeated-nodes

Conversation

@Darhazer
Copy link
Member

Fixes #996


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

@Darhazer Darhazer requested a review from a team as a code owner January 16, 2026 16:46
Comment on lines +18 to +23
def find_repeated_groups(items, key_proc:)
items
.group_by(&key_proc)
.values
.reject(&:one?)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be simpler to just use a block instead of passing a Proc instance as an argument?

Suggested change
def find_repeated_groups(items, key_proc:)
items
.group_by(&key_proc)
.values
.reject(&:one?)
end
def find_repeated_groups(items, &block)
items
.group_by(&block)
.values
.reject(&:one?)
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually found the code a bit confusing, when I tried rewriting it with an implicit block just now. If we do do that however, could we rename the block argument from &block to e.g. &signature_proc?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

Without keyword arguments to label things, it can be hard to tell what's going on from the caller’s side. In that case, the original way of passing a Proc via keyword arguments definitely has its perks. Alternatively, it might improve things somewhat to change the method name to something like find_repeated_groups_by, which clearly implies that grouping logic is expected.

Since both approaches seem to have their pros and cons, I felt that leaving it as it is would also be fine 👌

@r7kamura
Copy link
Contributor

As a general policy, I agree with this change 👍

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

Successfully merging this pull request may close these issues.

Extract helper module for duplicate detection

3 participants