Class: Prism::NumberedReferenceReadNode

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

Overview

Represents reading a numbered reference to a capture in the previous match.

$1
^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, number) ⇒ NumberedReferenceReadNode

Initialize a new NumberedReferenceReadNode node.



14747
14748
14749
14750
14751
14752
14753
# File 'lib/prism/node.rb', line 14747

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

Instance Attribute Details

#numberObject (readonly)

The (1-indexed, from the left) number of the capture group. Numbered references that are too large result in this value being 0.

$1          # number `1`

$5432       # number `5432`

$4294967296 # number `0`


14801
14802
14803
# File 'lib/prism/node.rb', line 14801

def number
  @number
end

Class Method Details

.typeObject

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



14814
14815
14816
# File 'lib/prism/node.rb', line 14814

def self.type
  :numbered_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.



14820
14821
14822
14823
# File 'lib/prism/node.rb', line 14820

def ===(other)
  other.is_a?(NumberedReferenceReadNode) &&
    (number === other.number)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



14756
14757
14758
# File 'lib/prism/node.rb', line 14756

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



14761
14762
14763
# File 'lib/prism/node.rb', line 14761

def child_nodes
  []
end

#comment_targetsObject

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



14777
14778
14779
# File 'lib/prism/node.rb', line 14777

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14772
14773
14774
# File 'lib/prism/node.rb', line 14772

def compact_child_nodes
  []
end

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

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?number: Integer) -> NumberedReferenceReadNode



14782
14783
14784
# File 'lib/prism/node.rb', line 14782

def copy(node_id: self.node_id, location: self.location, flags: self.flags, number: self.number)
  NumberedReferenceReadNode.new(source, node_id, location, flags, number)
end

#deconstruct_keys(keys) ⇒ Object

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



14790
14791
14792
# File 'lib/prism/node.rb', line 14790

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

#each_child_nodeObject

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



14766
14767
14768
14769
# File 'lib/prism/node.rb', line 14766

def each_child_node
  return to_enum(:each_child_node) unless block_given?

end

#inspectObject

def inspect -> String



14804
14805
14806
# File 'lib/prism/node.rb', line 14804

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



14809
14810
14811
# File 'lib/prism/node.rb', line 14809

def type
  :numbered_reference_read_node
end