Class: Prism::ConstantPathAndWriteNode

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) ⇒ ConstantPathAndWriteNode

Initialize a new ConstantPathAndWriteNode node.



4258
4259
4260
4261
4262
4263
4264
4265
4266
# File 'lib/prism/node.rb', line 4258

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



4302
4303
4304
# File 'lib/prism/node.rb', line 4302

def target
  @target
end

#valueObject (readonly)

attr_reader value: Prism::node



4312
4313
4314
# File 'lib/prism/node.rb', line 4312

def value
  @value
end

Class Method Details

.typeObject

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



4330
4331
4332
# File 'lib/prism/node.rb', line 4330

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



4336
4337
4338
4339
4340
4341
# File 'lib/prism/node.rb', line 4336

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



4269
4270
4271
# File 'lib/prism/node.rb', line 4269

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

#child_nodesObject Also known as: deconstruct

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



4274
4275
4276
# File 'lib/prism/node.rb', line 4274

def child_nodes
  [target, value]
end

#comment_targetsObject

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



4284
4285
4286
# File 'lib/prism/node.rb', line 4284

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



4279
4280
4281
# File 'lib/prism/node.rb', line 4279

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) -> ConstantPathAndWriteNode



4289
4290
4291
# File 'lib/prism/node.rb', line 4289

def copy(node_id: self.node_id, location: self.location, flags: self.flags, target: self.target, operator_loc: self.operator_loc, value: self.value)
  ConstantPathAndWriteNode.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 }



4297
4298
4299
# File 'lib/prism/node.rb', line 4297

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

#inspectObject

def inspect -> String



4320
4321
4322
# File 'lib/prism/node.rb', line 4320

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



4315
4316
4317
# File 'lib/prism/node.rb', line 4315

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



4305
4306
4307
4308
4309
# File 'lib/prism/node.rb', line 4305

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`.



4325
4326
4327
# File 'lib/prism/node.rb', line 4325

def type
  :constant_path_and_write_node
end