Class: Prism::ConstantPathOrWriteNode

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

Overview

Represents the use of the ‘||=` operator for assignment to a constant path.

Parent::Child ||= value
^^^^^^^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, target, operator_loc, value) ⇒ ConstantPathOrWriteNode

Initialize a new ConstantPathOrWriteNode node.



5341
5342
5343
5344
5345
5346
5347
5348
5349
# File 'lib/prism/node.rb', line 5341

def initialize(source, node_id, location, flags, target, operator_loc, value)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @target = target
  @operator_loc = operator_loc
  @value = value
end

Instance Attribute Details

#targetObject (readonly)

attr_reader target: ConstantPathNode



5385
5386
5387
# File 'lib/prism/node.rb', line 5385

def target
  @target
end

#valueObject (readonly)

attr_reader value: Prism::node



5401
5402
5403
# File 'lib/prism/node.rb', line 5401

def value
  @value
end

Class Method Details

.typeObject

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



5419
5420
5421
# File 'lib/prism/node.rb', line 5419

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



5425
5426
5427
5428
5429
5430
# File 'lib/prism/node.rb', line 5425

def ===(other)
  other.is_a?(ConstantPathOrWriteNode) &&
    (target === other.target) &&
    (operator_loc.nil? == other.operator_loc.nil?) &&
    (value === other.value)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



5352
5353
5354
# File 'lib/prism/node.rb', line 5352

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



5357
5358
5359
# File 'lib/prism/node.rb', line 5357

def child_nodes
  [target, value]
end

#comment_targetsObject

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



5367
5368
5369
# File 'lib/prism/node.rb', line 5367

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



5362
5363
5364
# File 'lib/prism/node.rb', line 5362

def compact_child_nodes
  [target, value]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?target: ConstantPathNode, ?operator_loc: Location, ?value: Prism::node) -> ConstantPathOrWriteNode



5372
5373
5374
# File 'lib/prism/node.rb', line 5372

def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value)
  ConstantPathOrWriteNode.new(source, node_id, location, flags, target, operator_loc, value)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, target: ConstantPathNode, operator_loc: Location, value: Prism::node }



5380
5381
5382
# File 'lib/prism/node.rb', line 5380

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

#inspectObject

def inspect -> String



5409
5410
5411
# File 'lib/prism/node.rb', line 5409

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



5404
5405
5406
# File 'lib/prism/node.rb', line 5404

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



5388
5389
5390
5391
5392
# File 'lib/prism/node.rb', line 5388

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

#save_operator_loc(repository) ⇒ Object

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



5396
5397
5398
# File 'lib/prism/node.rb', line 5396

def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc)
end

#typeObject

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



5414
5415
5416
# File 'lib/prism/node.rb', line 5414

def type
  :constant_path_or_write_node
end