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.



1406
1407
1408
1409
1410
1411
1412
# File 'lib/prism/node.rb', line 1406

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 `:$+`


1452
1453
1454
# File 'lib/prism/node.rb', line 1452

def name
  @name
end

Class Method Details

.typeObject

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



1465
1466
1467
# File 'lib/prism/node.rb', line 1465

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.



1471
1472
1473
1474
# File 'lib/prism/node.rb', line 1471

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



1415
1416
1417
# File 'lib/prism/node.rb', line 1415

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



1420
1421
1422
# File 'lib/prism/node.rb', line 1420

def child_nodes
  []
end

#comment_targetsObject

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



1430
1431
1432
# File 'lib/prism/node.rb', line 1430

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



1425
1426
1427
# File 'lib/prism/node.rb', line 1425

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



1435
1436
1437
# File 'lib/prism/node.rb', line 1435

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 }



1443
1444
1445
# File 'lib/prism/node.rb', line 1443

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

#inspectObject

def inspect -> String



1455
1456
1457
# File 'lib/prism/node.rb', line 1455

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



1460
1461
1462
# File 'lib/prism/node.rb', line 1460

def type
  :back_reference_read_node
end