Class: Reek::AST::ReferenceCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/ast/reference_collector.rb

Overview

Locates references to the current object within a portion of an abstract syntax tree.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast) ⇒ ReferenceCollector

Returns a new instance of ReferenceCollector.



10
11
12
# File 'lib/reek/ast/reference_collector.rb', line 10

def initialize(ast)
  @ast = ast
end

Instance Attribute Details

#astObject (readonly, private)

Returns the value of attribute ast.



20
21
22
# File 'lib/reek/ast/reference_collector.rb', line 20

def ast
  @ast
end

Instance Method Details

#explicit_self_callsObject (private)



22
23
24
# File 'lib/reek/ast/reference_collector.rb', line 22

def explicit_self_calls
  ast.each_node([:self, :super, :zsuper, :ivar, :ivasgn])
end

#implicit_self_callsObject (private)



26
27
28
# File 'lib/reek/ast/reference_collector.rb', line 26

def implicit_self_calls
  ast.each_node(:send).reject(&:receiver)
end

#num_refs_to_selfObject



14
15
16
# File 'lib/reek/ast/reference_collector.rb', line 14

def num_refs_to_self
  (explicit_self_calls.to_a + implicit_self_calls.to_a).size
end