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 SimpleForwardable

#def_delegators

Methods included from Descendence

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

Instance Method Details

#arityObject



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

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



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

def in_sequence_head
  super if children.empty?

  return unless (replace = children.first.in_sequence_head)

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