Sha256: 134986babf80dce089f5b9e4674dddb2ac23e05a44c5d352a4b3d2543d1a41c6

Contents?: true

Size: 688 Bytes

Versions: 9

Compression:

Stored size: 688 Bytes

Contents

require 'parser'

module Reek
  module Source
    # Base class for AST nodes extended with utility methods. Contains some
    # methods to ease the transition from Sexp to AST::Node.
    class AstNode < Parser::AST::Node
      def initialize(type, children = [], options = {})
        @comments = options.fetch(:comments, [])
        super
      end

      def comments
        @comments.map(&:text).join("\n")
      end

      # @deprecated
      def [](index)
        elements[index]
      end

      def line
        loc.line
      end

      # @deprecated
      def first
        type
      end

      private

      def elements
        [type, *children]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
reek-2.0.4 lib/reek/source/ast_node.rb
reek-2.0.3 lib/reek/source/ast_node.rb
reek-2.0.2 lib/reek/source/ast_node.rb
reek-2.0.1 lib/reek/source/ast_node.rb
reek-2.0.0 lib/reek/source/ast_node.rb
reek-1.6.6 lib/reek/source/ast_node.rb
reek-1.6.5 lib/reek/source/ast_node.rb
reek-1.6.4 lib/reek/source/ast_node.rb
reek-1.6.3 lib/reek/source/ast_node.rb