How to get nodes which represent autoload
statement?
#2696
Replies: 1 comment 1 reply
-
Hi @Super-Xray — those are all class AutoloadVisitor < Prism::Visitor
attr_reader :autoloads
def initialize(autoloads)
@autoloads = autoloads
end
def visit_call_node(node)
autoloads << node if node.name == :autoload
super
end
end
source = <<~RUBY
module Foo
autoload :Bar1, "bar.rb",
autoload :Bar2, "bar.rb"
autoload :Bar3, "bar.rb"
end
RUBY
autoloads = []
Prism.parse(source).value.accept(AutoloadVisitor.new(autoloads))
p autoloads # [#<Prism::CallNode>, #<Prism::CallNode>, #<Prism::CallNode>] you may want to additionally restrict it by checking if |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on using prism to derive statements like
autoload :Bar, "bar"
but I couldn't find which kind ofNode
contains this kind of statements. I had tried to search nodes definition which containsautoload
in the document and source codes and didn't find valid result.Beta Was this translation helpful? Give feedback.
All reactions