123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::AST::NodePattern::Node::Union

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: RuboCop::AST::NodePattern::Node
Defined in: lib/rubocop/ast/node_pattern/node.rb

Overview

Node class for { …​ }

Constant Summary

::RuboCop::AST::NodePattern::Node - Inherited

FunctionCall, INT_TO_RANGE, MAP, MATCHES_WITHIN_SET

Class Method Summary

Instance Attribute Summary

::RuboCop::AST::NodePattern::Node - Inherited

#capture?,
#matches_within_set?

that matches within a Set (e.g.

#rest?

To be overridden by subclasses.

#variadic?

Instance Method Summary

::RuboCop::AST::NodePattern::Node - Inherited

::RuboCop::AST::Descendence - Included

#child_nodes

Returns an array of child nodes.

#descendants

Returns an array of descendant nodes.

#each_child_node

Calls the given block for each child node.

#each_descendant

Calls the given block for each descendant node with depth first order.

#each_node

Calls the given block for the receiver and each descendant node in depth-first order.

Instance Method Details

#arity

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/node.rb', line 224

def arity
  minima, maxima = children.map { |child| child.arity_range.minmax }.transpose
  min = minima.min
  max = maxima.max
  min == max ? min : min..max
end

#in_sequence_head

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/node.rb', line 231

def in_sequence_head
  return unless children.any?(&:in_sequence_head)

  new_children = children.map do |child|
    next child unless (replace = child.in_sequence_head)

    if replace.size > 1
      Subsequence.new(:subsequence, replace, loc: child.loc)
    else
      replace.first
    end
  end

  [with(children: new_children)]
end

#nb_captures

Each child in a union must contain the same number of captures. Only one branch ends up capturing.

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/node.rb', line 249

def nb_captures
  child.nb_captures
end