Class: Prism::ConstantTargetNode

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

Overview

Represents writing to a constant in a context that doesn’t have an explicit value.

Foo, Bar = baz
^^^  ^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new ConstantTargetNode node.



6079
6080
6081
6082
6083
6084
6085
# File 'lib/prism/node.rb', line 6079

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)

attr_reader name: Symbol



6127
6128
6129
# File 'lib/prism/node.rb', line 6127

def name
  @name
end

Class Method Details

.typeObject

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



6140
6141
6142
# File 'lib/prism/node.rb', line 6140

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



6146
6147
6148
6149
# File 'lib/prism/node.rb', line 6146

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



6088
6089
6090
# File 'lib/prism/node.rb', line 6088

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



6093
6094
6095
# File 'lib/prism/node.rb', line 6093

def child_nodes
  []
end

#comment_targetsObject

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



6109
6110
6111
# File 'lib/prism/node.rb', line 6109

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



6104
6105
6106
# File 'lib/prism/node.rb', line 6104

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) -> ConstantTargetNode



6114
6115
6116
# File 'lib/prism/node.rb', line 6114

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name)
  ConstantTargetNode.new(source, node_id, location, flags, name)
end

#deconstruct_keys(keys) ⇒ Object

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



6122
6123
6124
# File 'lib/prism/node.rb', line 6122

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



6098
6099
6100
6101
# File 'lib/prism/node.rb', line 6098

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”



265
266
267
# File 'lib/prism/node_ext.rb', line 265

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]



260
261
262
# File 'lib/prism/node_ext.rb', line 260

def full_name_parts
  [name]
end

#inspectObject

def inspect -> String



6130
6131
6132
# File 'lib/prism/node.rb', line 6130

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



6135
6136
6137
# File 'lib/prism/node.rb', line 6135

def type
  :constant_target_node
end