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.



467
468
469
470
# File 'lib/pink_spoon/constant_resolver.rb', line 467

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

Instance Method Details

#find_all(ast) ⇒ Object



472
473
474
475
# File 'lib/pink_spoon/constant_resolver.rb', line 472

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

#visit_local_variable_operator_write_node(node) ⇒ Object



482
483
484
485
# File 'lib/pink_spoon/constant_resolver.rb', line 482

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



487
488
489
490
# File 'lib/pink_spoon/constant_resolver.rb', line 487

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



477
478
479
480
# File 'lib/pink_spoon/constant_resolver.rb', line 477

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