Class: Prism::ClassVariableAndWriteNode

Inherits:
PrismNode
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ ClassVariableAndWriteNode

Initialize a new ClassVariableAndWriteNode node.



3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
# File 'lib/prism/node.rb', line 3348

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

#nameObject (readonly)

attr_reader name: Symbol



3393
3394
3395
# File 'lib/prism/node.rb', line 3393

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



3410
3411
3412
# File 'lib/prism/node.rb', line 3410

def value
  @value
end

Class Method Details

.typeObject

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



3428
3429
3430
# File 'lib/prism/node.rb', line 3428

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.



3434
3435
3436
3437
3438
3439
3440
# File 'lib/prism/node.rb', line 3434

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



3360
3361
3362
# File 'lib/prism/node.rb', line 3360

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



3365
3366
3367
# File 'lib/prism/node.rb', line 3365

def child_nodes
  [value]
end

#comment_targetsObject

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



3375
3376
3377
# File 'lib/prism/node.rb', line 3375

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



3370
3371
3372
# File 'lib/prism/node.rb', line 3370

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



3380
3381
3382
# File 'lib/prism/node.rb', line 3380

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 }



3388
3389
3390
# File 'lib/prism/node.rb', line 3388

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

#desugarObject

:nodoc:



164
165
166
# File 'lib/prism/desugar_compiler.rb', line 164

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

#inspectObject

def inspect -> String



3418
3419
3420
# File 'lib/prism/node.rb', line 3418

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



3396
3397
3398
3399
3400
# File 'lib/prism/node.rb', line 3396

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

#operatorObject

def operator: () -> String



3413
3414
3415
# File 'lib/prism/node.rb', line 3413

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



3403
3404
3405
3406
3407
# File 'lib/prism/node.rb', line 3403

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

#typeObject

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



3423
3424
3425
# File 'lib/prism/node.rb', line 3423

def type
  :class_variable_and_write_node
end