Sha256: 45b61beabb8e244e5b53d2bf74d5210225da273e2622ec7439d3e18d9a2969c1

Contents?: true

Size: 652 Bytes

Versions: 5

Compression:

Stored size: 652 Bytes

Contents

# frozen_string_literal: true

module Reek
  module AST
    #
    # Locates references to the current object within a portion
    # of an abstract syntax tree.
    #
    class ReferenceCollector
      def initialize(ast)
        @ast = ast
      end

      def num_refs_to_self
        (explicit_self_calls + implicit_self_calls).size
      end

      private

      attr_reader :ast

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reek-4.7.3 lib/reek/ast/reference_collector.rb
reek-4.7.2 lib/reek/ast/reference_collector.rb
reek-4.7.1 lib/reek/ast/reference_collector.rb
reek-4.7.0 lib/reek/ast/reference_collector.rb
reek-4.6.2 lib/reek/ast/reference_collector.rb