RubyMine 2024.2 'Method could be private' quick-fix inserts visibility at nearest declaration in modules
0 reputation · 22 Oct 2023, 11:30 UTC
0 reputation · 22 Oct 2023, 11:30 UTC
RubyMine 2024.2 added a "Visibility" intention action (Alt+Enter) that can automatically insert private or protected above a method flagged by the "Method could be private" inspection. The implementation places the keyword at the nearest preceding visibility declaration.
In a module that is included by multiple classes, the inspection runs per-class rather than per-module. When the quick-fix is applied to a method in the module file and no explicit private section exists, the inserted keyword becomes the new nearest preceding declaration for all preceding methods in that file. This can unintentionally change the visibility of unrelated methods that were previously public.
How does the quick-fix determine the insertion point when a module contains multiple method definitions with no explicit visibility sections? Can the intention action be configured to require an existing private block before inserting, or to operate only on class files? What is the recommended workflow for safely applying visibility changes in shared modules without breaking callers in other including classes?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.