Class: Prism::ConstantReadNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantReadNode
- Defined in:
- lib/prism/node.rb,
lib/prism/node_ext.rb,
ext/prism/api_node.c
Overview
Represents referencing a constant.
Foo
^^^
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the [constant](github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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) -> ConstantReadNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol }.
-
#full_name ⇒ Object
Returns the full name of this constant.
-
#full_name_parts ⇒ Object
Returns the list of parts for the full name of this constant.
-
#initialize(source, node_id, location, flags, name) ⇒ ConstantReadNode
constructor
Initialize a new ConstantReadNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, name) ⇒ ConstantReadNode
Initialize a new ConstantReadNode node.
5608 5609 5610 5611 5612 5613 5614 |
# File 'lib/prism/node.rb', line 5608 def initialize(source, node_id, location, flags, name) @source = source @node_id = node_id @location = location @flags = flags @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the [constant](github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
X # name `:X`
SOME_CONSTANT # name `:SOME_CONSTANT`
5654 5655 5656 |
# File 'lib/prism/node.rb', line 5654 def name @name end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
5667 5668 5669 |
# File 'lib/prism/node.rb', line 5667 def self.type :constant_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.
5673 5674 5675 5676 |
# File 'lib/prism/node.rb', line 5673 def ===(other) other.is_a?(ConstantReadNode) && (name === other.name) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
5617 5618 5619 |
# File 'lib/prism/node.rb', line 5617 def accept(visitor) visitor.visit_constant_read_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
5622 5623 5624 |
# File 'lib/prism/node.rb', line 5622 def child_nodes [] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
5632 5633 5634 |
# File 'lib/prism/node.rb', line 5632 def comment_targets [] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
5627 5628 5629 |
# File 'lib/prism/node.rb', line 5627 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) -> ConstantReadNode
5637 5638 5639 |
# File 'lib/prism/node.rb', line 5637 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name) ConstantReadNode.new(source, node_id, location, flags, name) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol }
5645 5646 5647 |
# File 'lib/prism/node.rb', line 5645 def deconstruct_keys(keys) { node_id: node_id, location: location, name: name } end |
#full_name ⇒ Object
Returns the full name of this constant. For example: “Foo”
139 140 141 |
# File 'lib/prism/node_ext.rb', line 139 def full_name name.to_s end |
#full_name_parts ⇒ Object
Returns the list of parts for the full name of this constant. For example: [:Foo]
134 135 136 |
# File 'lib/prism/node_ext.rb', line 134 def full_name_parts [name] end |
#inspect ⇒ Object
def inspect -> String
5657 5658 5659 |
# File 'lib/prism/node.rb', line 5657 def inspect InspectVisitor.compose(self) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
5662 5663 5664 |
# File 'lib/prism/node.rb', line 5662 def type :constant_read_node end |