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.



5279
5280
5281
5282
5283
5284
5285
5286
5287
# File 'lib/prism/node.rb', line 5279

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



5323
5324
5325
# File 'lib/prism/node.rb', line 5323

def target
  @target
end

#valueObject (readonly)

attr_reader value: Prism::node



5339
5340
5341
# File 'lib/prism/node.rb', line 5339

def value
  @value
end

Class Method Details

.typeObject

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



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

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.



5363
5364
5365
5366
5367
5368
# File 'lib/prism/node.rb', line 5363

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



5290
5291
5292
# File 'lib/prism/node.rb', line 5290

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

#child_nodesObject Also known as: deconstruct

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



5295
5296
5297
# File 'lib/prism/node.rb', line 5295

def child_nodes
  [target, value]
end

#comment_targetsObject

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



5305
5306
5307
# File 'lib/prism/node.rb', line 5305

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



5300
5301
5302
# File 'lib/prism/node.rb', line 5300

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



5310
5311
5312
# File 'lib/prism/node.rb', line 5310

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 }



5318
5319
5320
# File 'lib/prism/node.rb', line 5318

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

#inspectObject

def inspect -> String



5347
5348
5349
# File 'lib/prism/node.rb', line 5347

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



5342
5343
5344
# File 'lib/prism/node.rb', line 5342

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



5326
5327
5328
5329
5330
# File 'lib/prism/node.rb', line 5326

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.



5334
5335
5336
# File 'lib/prism/node.rb', line 5334

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

#typeObject

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



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

def type
  :constant_path_or_write_node
end