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

Methods included from Descendence

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

Instance Method Details

#arityObject



225
226
227
228
229
230
# File 'lib/rubocop/ast/node_pattern/node.rb', line 225

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_headObject



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/rubocop/ast/node_pattern/node.rb', line 232

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