Class: Prism::ClassVariableOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ClassVariableOrWriteNode
- 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
attr_reader name: Symbol.
-
#value ⇒ Object
readonly
attr_reader value: Prism::node.
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) -> ClassVariableOrWriteNode.
-
#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) ⇒ ClassVariableOrWriteNode
constructor
Initialize a new ClassVariableOrWriteNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#name_loc ⇒ Object
attr_reader name_loc: Location.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location.
-
#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) ⇒ ClassVariableOrWriteNode
Initialize a new ClassVariableOrWriteNode node.
4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 |
# File 'lib/prism/node.rb', line 4511 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)
attr_reader name: Symbol
4563 4564 4565 |
# File 'lib/prism/node.rb', line 4563 def name @name end |
#value ⇒ Object (readonly)
attr_reader value: Prism::node
4592 4593 4594 |
# File 'lib/prism/node.rb', line 4592 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
4610 4611 4612 |
# File 'lib/prism/node.rb', line 4610 def self.type :class_variable_or_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.
4616 4617 4618 4619 4620 4621 4622 |
# File 'lib/prism/node.rb', line 4616 def ===(other) other.is_a?(ClassVariableOrWriteNode) && (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
4523 4524 4525 |
# File 'lib/prism/node.rb', line 4523 def accept(visitor) visitor.visit_class_variable_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
4528 4529 4530 |
# File 'lib/prism/node.rb', line 4528 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
4545 4546 4547 |
# File 'lib/prism/node.rb', line 4545 def comment_targets [name_loc, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
4540 4541 4542 |
# File 'lib/prism/node.rb', line 4540 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) -> ClassVariableOrWriteNode
4550 4551 4552 |
# File 'lib/prism/node.rb', line 4550 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) ClassVariableOrWriteNode.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 }
4558 4559 4560 |
# File 'lib/prism/node.rb', line 4558 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:
171 172 173 |
# File 'lib/prism/desugar_compiler.rb', line 171 def desugar # :nodoc: DesugarOrWriteDefinedNode.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
4533 4534 4535 4536 4537 |
# File 'lib/prism/node.rb', line 4533 def each_child_node return to_enum(:each_child_node) unless block_given? yield value end |
#inspect ⇒ Object
def inspect -> String
4600 4601 4602 |
# File 'lib/prism/node.rb', line 4600 def inspect InspectVisitor.compose(self) end |
#name_loc ⇒ Object
attr_reader name_loc: Location
4566 4567 4568 4569 4570 |
# File 'lib/prism/node.rb', line 4566 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
4595 4596 4597 |
# File 'lib/prism/node.rb', line 4595 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
4579 4580 4581 4582 4583 |
# File 'lib/prism/node.rb', line 4579 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.
4574 4575 4576 |
# File 'lib/prism/node.rb', line 4574 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.
4587 4588 4589 |
# File 'lib/prism/node.rb', line 4587 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`.
4605 4606 4607 |
# File 'lib/prism/node.rb', line 4605 def type :class_variable_or_write_node end |