Skip to content

Use .public_send instead of .send for calls to public methods - #23458

Open
AbishekRaj2007 wants to merge 1 commit into
Homebrew:mainfrom
AbishekRaj2007:send-to-public-send-cleanup
Open

Use .public_send instead of .send for calls to public methods#23458
AbishekRaj2007 wants to merge 1 commit into
Homebrew:mainfrom
AbishekRaj2007:send-to-public-send-cleanup

Conversation

@AbishekRaj2007

Copy link
Copy Markdown
Contributor

While going through the codebase for calls that use .send to invoke a method by a dynamic name, I found a batch of spots where the method being called is actually public .send was being used just to look up a method whose name isn't known until runtime (e.g. Tty.send(color), formula.send(spec_name)), not because anything private needed to be reached.

Since .send bypasses Ruby's private visibility check entirely, using it on public methods is a bit misleading to read — it makes a caller look like it might be reaching into internals when it isn't. public_send does the exact same dynamic lookup but only succeeds if the method is actually public, so it documents that intent and behaves identically here since every method involved already was public.

For each of the 20 call sites, I checked the receiver's class definition to confirm the method has no private marker before switching it over, so this should be a no-op behavior-wise.

Left untouched (need private access, so can't switch):

  • pour_bottle_check.rb - calls define_method, always private
  • api_hashable.rb - calls remove_const, always private
  • cli/parser.rb - calls a dynamically-named legacy _args method that may be defined by third-party tap commands; couldn't confirm it's always public, so left as-is to avoid breaking external taps

Note: I have used Claude Sonnet 5 only to change in code and carefully reviewed it before pushing and this PR was raised by myself and no AI is involved in writing the pr.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Copilot AI lite review requested due to automatic review settings August 6, 2026 16:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good so far! Please force-push to trigger CI again after the GitHub incident.

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.

3 participants