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.



4221
4222
4223
4224
4225
4226
4227
4228
4229
# File 'lib/prism/node.rb', line 4221

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



4265
4266
4267
# File 'lib/prism/node.rb', line 4265

def target
  @target
end

#valueObject (readonly)

attr_reader value: Prism::node



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

def value
  @value
end

Class Method Details

.typeObject

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



4293
4294
4295
# File 'lib/prism/node.rb', line 4293

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.



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

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



4232
4233
4234
# File 'lib/prism/node.rb', line 4232

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

#child_nodesObject Also known as: deconstruct

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



4237
4238
4239
# File 'lib/prism/node.rb', line 4237

def child_nodes
  [target, value]
end

#comment_targetsObject

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



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

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



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

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



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

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 }



4260
4261
4262
# File 'lib/prism/node.rb', line 4260

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

#inspectObject

def inspect -> String



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

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



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

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



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

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



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

def type
  :constant_path_and_write_node
end