class RuboCop::AST::NodePattern::Node

Base class for AST Nodes of a ‘NodePattern`

def arity

Returns:
  • (Integer, Range) - An Integer for fixed length terms, otherwise a Range.
def arity
  1
end

def arity_range

Returns:
  • (Range) - arity as a Range
def arity_range
  a = arity
  a.is_a?(Range) ? a : INT_TO_RANGE[a]
end

def capture?

def capture?
  false
end

def child

Returns:
  • (Node) - most nodes have only one child
def child
  children[0]
end

def children_nodes

Returns:
  • (Array) -
def children_nodes
  children.grep(Node)
end

def in_sequence_head

Returns:
  • (Array, nil) - replace node with result, or `nil` if no change requested.
def in_sequence_head
  nil
end

def matches_within_set?

Returns:
  • (Boolean) - returns true for nodes having a Ruby literal equivalent
def matches_within_set?
  MATCHES_WITHIN_SET.include?(type)
end

def nb_captures

Returns:
  • (Integer) - nb of captures of that node and its descendants
def nb_captures
  children_nodes.sum(&:nb_captures)
end

def rest?

def rest?
  false
end

def variadic?

Returns:
  • (Boolean) - returns true iff matches variable number of elements
def variadic?
  arity.is_a?(Range)
end

def with(type: @type, children: @children, location: @location)

def with(type: @type, children: @children, location: @location)
  self.class.new(type, children, { location: location })
end