# encoding: utf-8

module Rubocop
  module Cop
    # Handles adding and checking ignored nodes.
    module IgnoredNode
      def ignore_node(node)
        @ignored_nodes ||= []
        @ignored_nodes << node
      end

      def part_of_ignored_node?(node)
        return false unless @ignored_nodes
        expression = node.loc.expression
        @ignored_nodes.each do |ignored_node|
          if ignored_node.loc.expression.begin_pos <= expression.begin_pos &&
            ignored_node.loc.expression.end_pos >= expression.end_pos
            return true
          end
        end

        false
      end

      def ignored_node?(node)
        # Same object found in array?
        @ignored_nodes && @ignored_nodes.any? { |n| n.eql?(node) }
      end
    end
  end
end

# encoding: utf-8

module Rubocop
  module Cop
    # Handles adding and checking ignored nodes.
    module IgnoredNode
      def ignore_node(node)
        ignored_nodes << node
      end

      def part_of_ignored_node?(node)
        expression = node.loc.expression
        ignored_nodes.any? do |ignored_node|
          ignored_node.loc.expression.begin_pos <= expression.begin_pos &&
            ignored_node.loc.expression.end_pos >= expression.end_pos
        end
      end

      def ignored_node?(node)
        # Same object found in array?
        ignored_nodes.any? { |n| n.equal?(node) }
      end

      private

      def ignored_nodes
        @ignored_nodes ||= []
      end
    end
  end
end

Fix tests in the presence of `ast` 2.0.0
Fix tests in the presence of `ast` 2.0.0

`AST::Node` now implements `#eql?` which allows node equality checking.
Unfortunately this is not what was intended in Rubocop, so now we must
check object identity explicitly.
