class Ivar::MethodTargetedInstanceVariableReferenceVisitor
Visitor that collects instance variable references within a specific method definition
def initialize(file_path, target_method_name, target_line)
def initialize(file_path, target_method_name, target_line) super() @file_path = file_path @target_method_name = target_method_name @target_line = target_line @references = [] @in_target_method = false end
def visit_def_node(node)
def visit_def_node(node) # Check if this is our target method if node.name.to_sym == @target_method_name && node.location.start_line == @target_line # Found our target method, now collect all instance variable references within it collector = IvarCollector.new(@file_path, @target_method_name) node.body&.accept(collector) @references = collector.references false else # Sometimes methods are found inside other methods... node.body&.accept(self) true end end