class RuboCop::AST::NodePattern::Node
Base class for AST Nodes of a ‘NodePattern`
def arity
-
(Integer, Range)
- An Integer for fixed length terms, otherwise a Range.
def arity 1 end
def arity_range
-
(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
-
(Node)
- most nodes have only one child
def child children[0] end
def children_nodes
-
(Array
-)
def children_nodes children.grep(Node) end
def in_sequence_head
-
(Array
- replace node with result, or `nil` if no change requested., nil)
def in_sequence_head nil end
def matches_within_set?
-
(Boolean)
- returns true for nodes having a Ruby literal equivalent
def matches_within_set? MATCHES_WITHIN_SET.include?(type) end
def nb_captures
-
(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 source_range
def source_range loc.expression end
def variadic?
-
(Boolean)
- returns whether it matches a 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