Class: Prism::ConstantReadNode

Inherits:
PrismNode
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new ConstantReadNode node.



5996
5997
5998
5999
6000
6001
6002
# File 'lib/prism/node.rb', line 5996

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 [constant](github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).

X              # name `:X`

SOME_CONSTANT  # name `:SOME_CONSTANT`


6048
6049
6050
# File 'lib/prism/node.rb', line 6048

def name
  @name
end

Class Method Details

.typeObject

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



6061
6062
6063
# File 'lib/prism/node.rb', line 6061

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.



6067
6068
6069
6070
# File 'lib/prism/node.rb', line 6067

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



6005
6006
6007
# File 'lib/prism/node.rb', line 6005

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



6010
6011
6012
# File 'lib/prism/node.rb', line 6010

def child_nodes
  []
end

#comment_targetsObject

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



6026
6027
6028
# File 'lib/prism/node.rb', line 6026

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



6021
6022
6023
# File 'lib/prism/node.rb', line 6021

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



6031
6032
6033
# File 'lib/prism/node.rb', line 6031

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 }



6039
6040
6041
# File 'lib/prism/node.rb', line 6039

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



6015
6016
6017
6018
# File 'lib/prism/node.rb', line 6015

def each_child_node
  return to_enum(:each_child_node) unless block_given?

end

#full_nameObject

Returns the full name of this constant. For example: “Foo”



142
143
144
# File 'lib/prism/node_ext.rb', line 142

def full_name
  name.to_s
end

#full_name_partsObject

Returns the list of parts for the full name of this constant. For example: [:Foo]



137
138
139
# File 'lib/prism/node_ext.rb', line 137

def full_name_parts
  [name]
end

#inspectObject

def inspect -> String



6051
6052
6053
# File 'lib/prism/node.rb', line 6051

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



6056
6057
6058
# File 'lib/prism/node.rb', line 6056

def type
  :constant_read_node
end