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.



4977
4978
4979
4980
4981
4982
4983
4984
4985
# File 'lib/prism/node.rb', line 4977

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



5021
5022
5023
# File 'lib/prism/node.rb', line 5021

def target
  @target
end

#valueObject (readonly)

attr_reader value: Prism::node



5037
5038
5039
# File 'lib/prism/node.rb', line 5037

def value
  @value
end

Class Method Details

.typeObject

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



5055
5056
5057
# File 'lib/prism/node.rb', line 5055

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.



5061
5062
5063
5064
5065
5066
# File 'lib/prism/node.rb', line 5061

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



4988
4989
4990
# File 'lib/prism/node.rb', line 4988

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



4993
4994
4995
# File 'lib/prism/node.rb', line 4993

def child_nodes
  [target, value]
end

#comment_targetsObject

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



5003
5004
5005
# File 'lib/prism/node.rb', line 5003

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



4998
4999
5000
# File 'lib/prism/node.rb', line 4998

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



5008
5009
5010
# File 'lib/prism/node.rb', line 5008

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 }



5016
5017
5018
# File 'lib/prism/node.rb', line 5016

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

#inspectObject

def inspect -> String



5045
5046
5047
# File 'lib/prism/node.rb', line 5045

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



5040
5041
5042
# File 'lib/prism/node.rb', line 5040

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



5024
5025
5026
5027
5028
# File 'lib/prism/node.rb', line 5024

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.



5032
5033
5034
# File 'lib/prism/node.rb', line 5032

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

#typeObject

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



5050
5051
5052
# File 'lib/prism/node.rb', line 5050

def type
  :constant_path_and_write_node
end