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

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

Overview

Node class for `{ … }`

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


221
222
223
224
225
226
# File 'lib/rubocop/ast/node_pattern/node.rb', line 221

def arity
  minima, maxima = children.map(&:arity_range).map(&:minmax).transpose
  min = minima.min
  max = maxima.max
  min == max ? min : min..max
end

#in_sequence_headObject


228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/rubocop/ast/node_pattern/node.rb', line 228

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