Class: Yoda::AST::ParametersNode
- Inherits:
-
Node
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
#comments_by_vnode, #positionally_nearest_comment, #positionally_nearest_commenting_node
#location, #positionally_include?, #positionally_nearest_child, #range, #source_map
#all_nodes_lazy, #associate_comments, #comments, #wrapping?
#query, #query_all, #query_ancestor, #query_ancestors
#calc_current_location_method, #including_method, #method?
#calc_current_location_namespace, #full_name, #namespace, #namespace?, #namespace_path, #root?
Instance Method Details
#block_parameter_node ⇒ Node
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_nodes ⇒ 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?
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
|
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_clauses ⇒ Array<ParameterNode>
5
6
7
|
# File 'lib/yoda/ast/parameters_node.rb', line 5
def parameter_clauses
children
end
|
#parameter_nodes ⇒ 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
|
52
53
54
|
# File 'lib/yoda/ast/parameters_node.rb', line 52
def parameter_root
parameter_root_node.parameter
end
|
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_nodes ⇒ 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?
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
|