-
-
Notifications
You must be signed in to change notification settings - Fork 13
handle method definitions with constants #26
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -283,6 +283,7 @@ GEM | |
| zeitwerk (2.6.11) | ||
|
|
||
| PLATFORMS | ||
| arm64-darwin-21 | ||
| arm64-darwin-22 | ||
| x86_64-darwin-22 | ||
| x86_64-linux | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,7 +131,7 @@ def visit_def(node) | |
| elsif @modules.any? | ||
| @modules.last | ||
| else | ||
| @analyzer | ||
| inferred_context_for(target) | ||
| end | ||
|
|
||
| method_definition_args = { | ||
|
|
@@ -143,10 +143,12 @@ def visit_def(node) | |
| defined_files: [current_path], | ||
| } | ||
|
|
||
| if target == "self" | ||
| context.class_methods << ClassMethod.new(**method_definition_args) | ||
| else | ||
| # the method can define itself onto "self", or can have a target of a constant | ||
| # to define the class there. see #inferred_context_for for more | ||
| if target.nil? | ||
| context.instance_methods << InstanceMethod.new(**method_definition_args) | ||
| else | ||
| context.class_methods << ClassMethod.new(**method_definition_args) | ||
| end | ||
|
|
||
| @comments = [] | ||
|
|
@@ -188,4 +190,28 @@ def visit_command(node) | |
|
|
||
| super | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # handle method names like `Skiptrace.current_bindings` where the constant | ||
| # wasn't already visited | ||
| # rubocop:disable Lint/AssignmentInCondition | ||
| def inferred_context_for(target) | ||
| if existing = @analyzer.modules.detect { |name| name.qualified_name == target } | ||
| return prev if @modules.find { |mod| mod.qualified_name == existing.qualified_name } | ||
|
|
||
| @modules << existing | ||
| @namespace << existing | ||
|
Comment on lines
+203
to
+204
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we shouldn't add it to the |
||
| return existing | ||
|
|
||
| elsif existing = @analyzer.classes.detect { |name| name.qualified_name == target } | ||
| return prev if @classes.find { |klass| klass.qualified_name == existing.qualified_name } | ||
|
|
||
| @classes << existing | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| return existing | ||
|
|
||
| end | ||
| @analyzer | ||
| end | ||
| # rubocop:enable Lint/AssignmentInCondition | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is
prevcoming from? 🤔