Class: Prism::ClassVariableOperatorWriteNode

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

Overview

Represents assigning to a class variable using an operator that isn’t ‘=`.

@@target += value
^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator) ⇒ ClassVariableOperatorWriteNode

Initialize a new ClassVariableOperatorWriteNode node.



4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
# File 'lib/prism/node.rb', line 4165

def initialize(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @name = name
  @name_loc = name_loc
  @binary_operator_loc = binary_operator_loc
  @value = value
  @binary_operator = binary_operator
end

Instance Attribute Details

#binary_operatorObject (readonly)

attr_reader binary_operator: Symbol



4243
4244
4245
# File 'lib/prism/node.rb', line 4243

def binary_operator
  @binary_operator
end

#nameObject (readonly)

attr_reader name: Symbol



4211
4212
4213
# File 'lib/prism/node.rb', line 4211

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



4240
4241
4242
# File 'lib/prism/node.rb', line 4240

def value
  @value
end

Class Method Details

.typeObject

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



4256
4257
4258
# File 'lib/prism/node.rb', line 4256

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



4262
4263
4264
4265
4266
4267
4268
4269
# File 'lib/prism/node.rb', line 4262

def ===(other)
  other.is_a?(ClassVariableOperatorWriteNode) &&
    (name === other.name) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
    (value === other.value) &&
    (binary_operator === other.binary_operator)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



4178
4179
4180
# File 'lib/prism/node.rb', line 4178

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

#binary_operator_locObject

attr_reader binary_operator_loc: Location



4227
4228
4229
4230
4231
# File 'lib/prism/node.rb', line 4227

def binary_operator_loc
  location = @binary_operator_loc
  return location if location.is_a?(Location)
  @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



4183
4184
4185
# File 'lib/prism/node.rb', line 4183

def child_nodes
  [value]
end

#comment_targetsObject

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



4193
4194
4195
# File 'lib/prism/node.rb', line 4193

def comment_targets
  [name_loc, binary_operator_loc, value] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



4188
4189
4190
# File 'lib/prism/node.rb', line 4188

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, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?binary_operator_loc: Location, ?value: Prism::node, ?binary_operator: Symbol) -> ClassVariableOperatorWriteNode



4198
4199
4200
# File 'lib/prism/node.rb', line 4198

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator)
  ClassVariableOperatorWriteNode.new(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, binary_operator_loc: Location, value: Prism::node, binary_operator: Symbol }



4206
4207
4208
# File 'lib/prism/node.rb', line 4206

def deconstruct_keys(keys)
  { node_id: node_id, location: location, name: name, name_loc: name_loc, binary_operator_loc: binary_operator_loc, value: value, binary_operator: binary_operator }
end

#desugarObject

:nodoc:



177
178
179
# File 'lib/prism/desugar_compiler.rb', line 177

def desugar # :nodoc:
  DesugarOperatorWriteNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
end

#inspectObject

def inspect -> String



4246
4247
4248
# File 'lib/prism/node.rb', line 4246

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



4214
4215
4216
4217
4218
# File 'lib/prism/node.rb', line 4214

def name_loc
  location = @name_loc
  return location if location.is_a?(Location)
  @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#operatorObject

Returns the binary operator used to modify the receiver. This method is deprecated in favor of #binary_operator.



358
359
360
361
# File 'lib/prism/node_ext.rb', line 358

def operator
  deprecated("binary_operator")
  binary_operator
end

#operator_locObject

Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of #binary_operator_loc.



365
366
367
368
# File 'lib/prism/node_ext.rb', line 365

def operator_loc
  deprecated("binary_operator_loc")
  binary_operator_loc
end

#save_binary_operator_loc(repository) ⇒ Object

Save the binary_operator_loc location using the given saved source so that it can be retrieved later.



4235
4236
4237
# File 'lib/prism/node.rb', line 4235

def save_binary_operator_loc(repository)
  repository.enter(node_id, :binary_operator_loc)
end

#save_name_loc(repository) ⇒ Object

Save the name_loc location using the given saved source so that it can be retrieved later.



4222
4223
4224
# File 'lib/prism/node.rb', line 4222

def save_name_loc(repository)
  repository.enter(node_id, :name_loc)
end

#typeObject

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



4251
4252
4253
# File 'lib/prism/node.rb', line 4251

def type
  :class_variable_operator_write_node
end