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.



4871
4872
4873
4874
4875
4876
4877
# File 'lib/prism/node.rb', line 4871

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`


4917
4918
4919
# File 'lib/prism/node.rb', line 4917

def name
  @name
end

Class Method Details

.typeObject

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



4930
4931
4932
# File 'lib/prism/node.rb', line 4930

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.



4936
4937
4938
4939
# File 'lib/prism/node.rb', line 4936

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



4880
4881
4882
# File 'lib/prism/node.rb', line 4880

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

#child_nodesObject Also known as: deconstruct

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



4885
4886
4887
# File 'lib/prism/node.rb', line 4885

def child_nodes
  []
end

#comment_targetsObject

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



4895
4896
4897
# File 'lib/prism/node.rb', line 4895

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



4890
4891
4892
# File 'lib/prism/node.rb', line 4890

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



4900
4901
4902
# File 'lib/prism/node.rb', line 4900

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 }



4908
4909
4910
# File 'lib/prism/node.rb', line 4908

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

#full_nameObject

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_partsObject

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

#inspectObject

def inspect -> String



4920
4921
4922
# File 'lib/prism/node.rb', line 4920

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



4925
4926
4927
# File 'lib/prism/node.rb', line 4925

def type
  :constant_read_node
end