Class: Prism::BackReferenceReadNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents reading a reference to a field in the previous match.

$'
^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name) ⇒ BackReferenceReadNode

Initialize a new BackReferenceReadNode node.



1504
1505
1506
1507
1508
1509
1510
# File 'lib/prism/node.rb', line 1504

def initialize(source, node_id, location, flags, name)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

The name of the back-reference variable, including the leading ‘$`.

$& # name `:$&`

$+ # name `:$+`


1556
1557
1558
# File 'lib/prism/node.rb', line 1556

def name
  @name
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See Node::type.



1569
1570
1571
# File 'lib/prism/node.rb', line 1569

def self.type
  :back_reference_read_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



1575
1576
1577
1578
# File 'lib/prism/node.rb', line 1575

def ===(other)
  other.is_a?(BackReferenceReadNode) &&
    (name === other.name)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



1513
1514
1515
# File 'lib/prism/node.rb', line 1513

def accept(visitor)
  visitor.visit_back_reference_read_node(self)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



1518
1519
1520
# File 'lib/prism/node.rb', line 1518

def child_nodes
  []
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



1534
1535
1536
# File 'lib/prism/node.rb', line 1534

def comment_targets
  [] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



1529
1530
1531
# File 'lib/prism/node.rb', line 1529

def compact_child_nodes
  []
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol) -> BackReferenceReadNode



1539
1540
1541
# File 'lib/prism/node.rb', line 1539

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
  BackReferenceReadNode.new(source, node_id, location, flags, name)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol }



1547
1548
1549
# File 'lib/prism/node.rb', line 1547

def deconstruct_keys(keys)
  { node_id: node_id, location: location, name: name }
end

#each_child_nodeObject

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator



1523
1524
1525
1526
# File 'lib/prism/node.rb', line 1523

def each_child_node
  return to_enum(:each_child_node) unless block_given?

end

#inspectObject

def inspect -> String



1559
1560
1561
# File 'lib/prism/node.rb', line 1559

def inspect
  InspectVisitor.compose(self)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



1564
1565
1566
# File 'lib/prism/node.rb', line 1564

def type
  :back_reference_read_node
end