Class: PinkSpoon::ConstantResolver::LocalAssignmentFinder

Inherits:
Prism::Visitor
  • Object
show all
Defined in:
lib/pink_spoon/constant_resolver.rb

Overview

Collects all RHS nodes for ‘var_name = <rhs>` local variable writes.

Instance Method Summary collapse

Constructor Details

#initialize(var_name) ⇒ LocalAssignmentFinder

Returns a new instance of LocalAssignmentFinder.



404
405
406
407
# File 'lib/pink_spoon/constant_resolver.rb', line 404

def initialize(var_name)
  @var_name = var_name
  @results  = []
end

Instance Method Details

#find_all(ast) ⇒ Object



409
410
411
412
# File 'lib/pink_spoon/constant_resolver.rb', line 409

def find_all(ast)
  visit(ast)
  @results
end

#visit_local_variable_operator_write_node(node) ⇒ Object



419
420
421
422
# File 'lib/pink_spoon/constant_resolver.rb', line 419

def visit_local_variable_operator_write_node(node)
  @results << node.value if node.name.to_s == @var_name
  super
end

#visit_local_variable_or_write_node(node) ⇒ Object



424
425
426
427
# File 'lib/pink_spoon/constant_resolver.rb', line 424

def visit_local_variable_or_write_node(node)
  @results << node.value if node.name.to_s == @var_name
  super
end

#visit_local_variable_write_node(node) ⇒ Object



414
415
416
417
# File 'lib/pink_spoon/constant_resolver.rb', line 414

def visit_local_variable_write_node(node)
  @results << node.value if node.name.to_s == @var_name
  super
end