Class: RuboCop::AST::NodePattern::Node::Subsequence

Inherits:
RuboCop::AST::NodePattern::Node show all
Includes:
ForbidInSeqHead
Defined in:
lib/rubocop/ast/node_pattern/node.rb

Overview

A list (potentially empty) of nodes; part of a Union

Constant Summary

Constants inherited from RuboCop::AST::NodePattern::Node

FunctionCall, MAP

Instance Method Summary collapse

Methods inherited from RuboCop::AST::NodePattern::Node

#arity_range, #capture?, #child, #children_nodes, #matches_within_set?, #nb_captures, #rest?, #variadic?, #with

Methods included from Descendence

#child_nodes, #descendants, #each_child_node, #each_descendant, #each_node

Instance Method Details

#arityObject



205
206
207
208
# File 'lib/rubocop/ast/node_pattern/node.rb', line 205

def arity
  min, max = children.map(&:arity_range).map(&:minmax).transpose.map(&:sum)
  min == max ? min || 0 : min..max # NOTE: || 0 for empty case, where min == max == nil.
end

#in_sequence_headObject



210
211
212
213
214
215
216
# File 'lib/rubocop/ast/node_pattern/node.rb', line 210

def in_sequence_head
  super if children.empty?

  return unless (replace = children.first.in_sequence_head)

  [with(children: [*replace, *children[1..-1]])]
end