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:.
-
#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.
4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 |
# File 'lib/prism/node.rb', line 4008 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`
^^^^^^^^
4056 4057 4058 |
# File 'lib/prism/node.rb', line 4056 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
^^^^^
4094 4095 4096 |
# File 'lib/prism/node.rb', line 4094 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
4112 4113 4114 |
# File 'lib/prism/node.rb', line 4112 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.
4118 4119 4120 4121 4122 4123 4124 |
# File 'lib/prism/node.rb', line 4118 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
4020 4021 4022 |
# File 'lib/prism/node.rb', line 4020 def accept(visitor) visitor.visit_class_variable_and_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
4025 4026 4027 |
# File 'lib/prism/node.rb', line 4025 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
4035 4036 4037 |
# File 'lib/prism/node.rb', line 4035 def comment_targets [name_loc, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
4030 4031 4032 |
# File 'lib/prism/node.rb', line 4030 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
4040 4041 4042 |
# File 'lib/prism/node.rb', line 4040 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 }
4048 4049 4050 |
# File 'lib/prism/node.rb', line 4048 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 |
#inspect ⇒ Object
def inspect -> String
4102 4103 4104 |
# File 'lib/prism/node.rb', line 4102 def inspect InspectVisitor.compose(self) end |
#name_loc ⇒ Object
Represents the location of the variable name.
@@target &&= value
^^^^^^^^
4062 4063 4064 4065 4066 |
# File 'lib/prism/node.rb', line 4062 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
4097 4098 4099 |
# File 'lib/prism/node.rb', line 4097 def operator operator_loc.slice end |
#operator_loc ⇒ Object
Represents the location of the ‘&&=` operator.
@@target &&= value
^^^
4078 4079 4080 4081 4082 |
# File 'lib/prism/node.rb', line 4078 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.
4070 4071 4072 |
# File 'lib/prism/node.rb', line 4070 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.
4086 4087 4088 |
# File 'lib/prism/node.rb', line 4086 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`.
4107 4108 4109 |
# File 'lib/prism/node.rb', line 4107 def type :class_variable_and_write_node end |