Sha256: fec1d4a7a229181b6e247bf9ef8274d24b5972f69b0e3e44ee37e1253a33e83f

Contents?: true

Size: 717 Bytes

Versions: 5

Compression:

Stored size: 717 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
      attr_reader :comments

      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

5 entries across 5 versions & 1 rubygems

Version Path
reek-1.6.2 lib/reek/source/ast_node.rb
reek-1.6.1 lib/reek/source/ast_node.rb
reek-1.6.0 lib/reek/source/ast_node.rb
reek-1.5.1 lib/reek/source/ast_node.rb
reek-1.5.0 lib/reek/source/ast_node.rb