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.



1199
1200
1201
1202
1203
1204
1205
# File 'lib/prism/node.rb', line 1199

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


1245
1246
1247
# File 'lib/prism/node.rb', line 1245

def name
  @name
end

Class Method Details

.typeObject

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



1258
1259
1260
# File 'lib/prism/node.rb', line 1258

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.



1264
1265
1266
1267
# File 'lib/prism/node.rb', line 1264

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



1208
1209
1210
# File 'lib/prism/node.rb', line 1208

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

#child_nodesObject Also known as: deconstruct

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



1213
1214
1215
# File 'lib/prism/node.rb', line 1213

def child_nodes
  []
end

#comment_targetsObject

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



1223
1224
1225
# File 'lib/prism/node.rb', line 1223

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



1218
1219
1220
# File 'lib/prism/node.rb', line 1218

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



1228
1229
1230
# File 'lib/prism/node.rb', line 1228

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 }



1236
1237
1238
# File 'lib/prism/node.rb', line 1236

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

#inspectObject

def inspect -> String



1248
1249
1250
# File 'lib/prism/node.rb', line 1248

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



1253
1254
1255
# File 'lib/prism/node.rb', line 1253

def type
  :back_reference_read_node
end