Class: Yoda::AST::ParametersNode

Inherits:
Node
  • Object
show all
Defined in:
lib/yoda/ast/parameters_node.rb

Instance Attribute Summary

Attributes inherited from Node

#node

Attributes inherited from Vnode

#comments_by_node, #parent

Instance Method Summary collapse

Methods inherited from Node

#children, #identifier, #initialize, #kind, #source_map

Methods inherited from Vnode

#children, #constant?, #empty?, #identifier, #initialize, #inspect, #inspect_content, #nesting, #present?, #try, #type, #wrap_child

Methods included from Vnode::CommentPositional

#comments_by_vnode, #positionally_nearest_comment, #positionally_nearest_commenting_node

Methods included from Vnode::Positional

#location, #positionally_include?, #positionally_nearest_child, #range, #source_map

Methods included from Vnode::CommentAssociation

#all_nodes_lazy, #associate_comments, #comments, #wrapping?

Methods included from Traversable

#query, #query_all, #query_ancestor, #query_ancestors

Methods included from MethodTraversable

#calc_current_location_method, #including_method, #method?

Methods included from NamespaceTraversable

#calc_current_location_namespace, #full_name, #namespace, #namespace?, #namespace_path, #root?

Constructor Details

This class inherits a constructor from Yoda::AST::Node

Instance Method Details

#block_parameter_nodeNode

Returns:



47
48
49
# File 'lib/yoda/ast/parameters_node.rb', line 47

def block_parameter_node
  @block_parameter_node ||= children.find { |arg_node| arg_node.type == :blockarg }
end

#keyword_parameter_nodesArray<::AST::Node>

Returns:

  • (Array<::AST::Node>)


37
38
39
# File 'lib/yoda/ast/parameters_node.rb', line 37

def keyword_parameter_nodes
  @keyword_parameter_nodes ||= children.select { |arg_node| %i(kwarg kwoptarg).include?(arg_node.type) }
end

#keyword_rest_parameter_node::AST::Node?

Returns:

  • (::AST::Node, nil)


42
43
44
# File 'lib/yoda/ast/parameters_node.rb', line 42

def keyword_rest_parameter_node
  @keyword_rest_parameter_node ||= children.find { |arg_node| arg_node.type == :kwrestarg }
end

#parameterModel::Parameters::Multiple



10
11
12
13
14
15
16
17
18
19
# File 'lib/yoda/ast/parameters_node.rb', line 10

def parameter
  Model::Parameters::Multiple.new(
    parameters: parameter_nodes.map(&:parameter),
    rest_parameter: rest_parameter_node&.parameter,
    post_parameters: post_parameter_nodes.map(&:parameter),
    keyword_parameters: keyword_parameter_nodes.map(&:parameter),
    keyword_rest_parameter: keyword_rest_parameter_node&.parameter,
    block_parameter: block_parameter_node&.parameter,
  )
end

#parameter_clausesArray<ParameterNode>

Returns:



5
6
7
# File 'lib/yoda/ast/parameters_node.rb', line 5

def parameter_clauses
  children
end

#parameter_nodesArray<::AST::Node>

Returns:

  • (Array<::AST::Node>)


22
23
24
# File 'lib/yoda/ast/parameters_node.rb', line 22

def parameter_nodes
  @parameter_nodes ||= children.take_while { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) }
end

#parameter_rootModel::Parameters::Base



52
53
54
# File 'lib/yoda/ast/parameters_node.rb', line 52

def parameter_root
  parameter_root_node.parameter
end

#parameter_root_nodeParametersNode

Returns:



57
58
59
# File 'lib/yoda/ast/parameters_node.rb', line 57

def parameter_root_node
  parent.try(:parameter_root_node) || self
end

#post_parameter_nodesArray<::AST::Node>

Returns:

  • (Array<::AST::Node>)


32
33
34
# File 'lib/yoda/ast/parameters_node.rb', line 32

def post_parameter_nodes
  @post_parameter_nodes ||= 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

#rest_parameter_node::AST::Node?

Returns:

  • (::AST::Node, nil)


27
28
29
# File 'lib/yoda/ast/parameters_node.rb', line 27

def rest_parameter_node
  @rest_parameter_node ||= children.find { |arg_node| arg_node.type == :restarg }
end