Sha256: c6cf9294e3d0c21df6b56833d5247de28fb3f946c6946ceef29d82d6722f8922

Contents?: true

Size: 943 Bytes

Versions: 4

Compression:

Stored size: 943 Bytes

Contents

module Yoda
  module Parsing
    module NodeObjects
      class MlhsNode
        # @param node [::AST::Node]
        attr_reader :node

        # @param node [::AST::Node]
        def initialize(node)
          fail ArgumentError, node unless node.is_a?(::AST::Node) && node.type == :mlhs
          @node = node
        end

        # @return [Array<::AST::Node>]
        def pre_nodes
          @pre_nodes ||= node.children.take_while { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) }
        end

        # @return [::AST::Node, nil]
        def rest_node
          @rest_node ||= node.children.find { |arg_node| arg_node.type == :restarg }
        end

        # @return [Array<::AST::Node>]
        def post_nodes
          @post_nodes ||= node.children.drop_while { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) }.select { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) }
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yoda-language-server-0.10.1 lib/yoda/parsing/node_objects/mlhs_node.rb
yoda-language-server-0.10.0 lib/yoda/parsing/node_objects/mlhs_node.rb
yoda-language-server-0.9.0 lib/yoda/parsing/node_objects/mlhs_node.rb
yoda-language-server-0.8.0 lib/yoda/parsing/node_objects/mlhs_node.rb