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.



493
494
495
496
# File 'lib/pink_spoon/constant_resolver.rb', line 493

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

Instance Method Details

#find_all(ast) ⇒ Object



498
499
500
501
# File 'lib/pink_spoon/constant_resolver.rb', line 498

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

#visit_local_variable_operator_write_node(node) ⇒ Object



508
509
510
511
# File 'lib/pink_spoon/constant_resolver.rb', line 508

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



513
514
515
516
# File 'lib/pink_spoon/constant_resolver.rb', line 513

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



503
504
505
506
# File 'lib/pink_spoon/constant_resolver.rb', line 503

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