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?, #source_range, #variadic?, #with

Methods included from Descendence

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

Instance Method Details

#arityObject



209
210
211
212
# File 'lib/rubocop/ast/node_pattern/node.rb', line 209

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

#in_sequence_headObject



214
215
216
217
218
219
220
# File 'lib/rubocop/ast/node_pattern/node.rb', line 214

def in_sequence_head
  super if children.empty?

  return unless (replace = children.first.in_sequence_head)

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