Class: Prism::ClassVariableAndWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ClassVariableAndWriteNode
- Defined in:
- lib/prism/node.rb,
lib/prism/desugar_compiler.rb,
ext/prism/api_node.c
Overview
Represents the use of the ‘&&=` operator for assignment to a class variable.
@@target &&= value
^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the class variable, which is a ‘@@` followed by an [identifier](github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
-
#value ⇒ Object
readonly
Represents the value being assigned.
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.
-
#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, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> ClassVariableAndWriteNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }.
-
#desugar ⇒ Object
:nodoc:.
-
#each_child_node {|value| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ ClassVariableAndWriteNode
constructor
Initialize a new ClassVariableAndWriteNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#name_loc ⇒ Object
Represents the location of the variable name.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
Represents the location of the ‘&&=` operator.
-
#save_name_loc(repository) ⇒ Object
Save the name_loc location using the given saved source so that it can be retrieved later.
-
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ ClassVariableAndWriteNode
Initialize a new ClassVariableAndWriteNode node.
4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 |
# File 'lib/prism/node.rb', line 4259 def initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) @source = source @node_id = node_id @location = location @flags = flags @name = name @name_loc = name_loc @operator_loc = operator_loc @value = value end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the class variable, which is a ‘@@` followed by an [identifier](github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
@@target &&= value # name `:@@target`
^^^^^^^^
4314 4315 4316 |
# File 'lib/prism/node.rb', line 4314 def name @name end |
#value ⇒ Object (readonly)
Represents the value being assigned. This can be any [non-void expression](github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
@@target &&= value
^^^^^
4352 4353 4354 |
# File 'lib/prism/node.rb', line 4352 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
4370 4371 4372 |
# File 'lib/prism/node.rb', line 4370 def self.type :class_variable_and_write_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.
4376 4377 4378 4379 4380 4381 4382 |
# File 'lib/prism/node.rb', line 4376 def ===(other) other.is_a?(ClassVariableAndWriteNode) && (name === other.name) && (name_loc.nil? == other.name_loc.nil?) && (operator_loc.nil? == other.operator_loc.nil?) && (value === other.value) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
4271 4272 4273 |
# File 'lib/prism/node.rb', line 4271 def accept(visitor) visitor.visit_class_variable_and_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
4276 4277 4278 |
# File 'lib/prism/node.rb', line 4276 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
4293 4294 4295 |
# File 'lib/prism/node.rb', line 4293 def comment_targets [name_loc, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
4288 4289 4290 |
# File 'lib/prism/node.rb', line 4288 def compact_child_nodes [value] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> ClassVariableAndWriteNode
4298 4299 4300 |
# File 'lib/prism/node.rb', line 4298 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value) ClassVariableAndWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
4306 4307 4308 |
# File 'lib/prism/node.rb', line 4306 def deconstruct_keys(keys) { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value } end |
#desugar ⇒ Object
:nodoc:
165 166 167 |
# File 'lib/prism/desugar_compiler.rb', line 165 def desugar # :nodoc: DesugarAndWriteNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile end |
#each_child_node {|value| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator
4281 4282 4283 4284 4285 |
# File 'lib/prism/node.rb', line 4281 def each_child_node return to_enum(:each_child_node) unless block_given? yield value end |
#inspect ⇒ Object
def inspect -> String
4360 4361 4362 |
# File 'lib/prism/node.rb', line 4360 def inspect InspectVisitor.compose(self) end |
#name_loc ⇒ Object
Represents the location of the variable name.
@@target &&= value
^^^^^^^^
4320 4321 4322 4323 4324 |
# File 'lib/prism/node.rb', line 4320 def name_loc location = @name_loc return location if location.is_a?(Location) @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ Object
def operator: () -> String
4355 4356 4357 |
# File 'lib/prism/node.rb', line 4355 def operator operator_loc.slice end |
#operator_loc ⇒ Object
Represents the location of the ‘&&=` operator.
@@target &&= value
^^^
4336 4337 4338 4339 4340 |
# File 'lib/prism/node.rb', line 4336 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#save_name_loc(repository) ⇒ Object
Save the name_loc location using the given saved source so that it can be retrieved later.
4328 4329 4330 |
# File 'lib/prism/node.rb', line 4328 def save_name_loc(repository) repository.enter(node_id, :name_loc) end |
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
4344 4345 4346 |
# File 'lib/prism/node.rb', line 4344 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
4365 4366 4367 |
# File 'lib/prism/node.rb', line 4365 def type :class_variable_and_write_node end |