123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Namespace Children
Modules:
Classes:
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::RuboCop::SimpleForwardable, Parser::AST::Node
Instance Chain:
self, ::RuboCop::AST::Descendence, Parser::AST::Node
Inherits: Parser::AST::Node
  • Object
Defined in: lib/rubocop/ast/node_pattern/node.rb

Overview

Base class for AST Nodes of a NodePattern

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::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 Attribute Details

#capture?Boolean (readonly)

[ GitHub ]

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

def capture?
  false
end

#matches_within_set?Boolean (readonly)

that matches within a Set (e.g. 42, :sym but not /regexp/)

Returns:

  • (Boolean)

    returns true for nodes having a Ruby literal equivalent

[ GitHub ]

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

def matches_within_set?
  MATCHES_WITHIN_SET.include?(type)
end

#rest?Boolean (readonly)

To be overridden by subclasses

[ GitHub ]

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

def rest?
  false
end

#variadic?Boolean (readonly)

Returns:

  • (Boolean)

    returns whether it matches a variable number of elements

[ GitHub ]

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

def variadic?
  arity.is_a?(Range)
end

Instance Method Details

#arityInteger, Range

Note: arity.end may be Float::INFINITY

Returns:

  • (Integer, Range)

    An Integer for fixed length terms, otherwise a Range.

[ GitHub ]

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

def arity
  1
end

#arity_rangeRange

Returns:

  • (Range)

    arity as a Range

[ GitHub ]

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

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

#childNode

Returns:

  • (Node)

    most nodes have only one child

[ GitHub ]

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

def child
  children[0]
end

#children_nodesArray<Node>

[ GitHub ]

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

def children_nodes
  children.grep(Node)
end

#in_sequence_headArray<Node>?

Returns:

  • (Array<Node>, nil)

    replace node with result, or nil if no change requested.

[ GitHub ]

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

def in_sequence_head
  nil
end

#nb_capturesInteger

Returns:

  • (Integer)

    nb of captures that this node will emit

[ GitHub ]

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

def nb_captures
  children_nodes.sum(&:nb_captures)
end

#source_range

[ GitHub ]

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

def source_range
  loc.expression
end

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

[ GitHub ]

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

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