Class: Prism::GlobalVariableAndWriteNode

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

Overview

Represents the use of the ‘&&=` operator for assignment to a global variable.

$target &&= value
^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ GlobalVariableAndWriteNode

Initialize a new GlobalVariableAndWriteNode node.



8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
# File 'lib/prism/node.rb', line 8104

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

Instance Attribute Details

#nameObject (readonly)

attr_reader name: Symbol



8156
8157
8158
# File 'lib/prism/node.rb', line 8156

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



8185
8186
8187
# File 'lib/prism/node.rb', line 8185

def value
  @value
end

Class Method Details

.typeObject

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



8203
8204
8205
# File 'lib/prism/node.rb', line 8203

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



8209
8210
8211
8212
8213
8214
8215
# File 'lib/prism/node.rb', line 8209

def ===(other)
  other.is_a?(GlobalVariableAndWriteNode) &&
    (name === other.name) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (operator_loc.nil? == other.operator_loc.nil?) &&
    (value === other.value)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



8116
8117
8118
# File 'lib/prism/node.rb', line 8116

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



8121
8122
8123
# File 'lib/prism/node.rb', line 8121

def child_nodes
  [value]
end

#comment_targetsObject

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



8138
8139
8140
# File 'lib/prism/node.rb', line 8138

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



8133
8134
8135
# File 'lib/prism/node.rb', line 8133

def compact_child_nodes
  [value]
end

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

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> GlobalVariableAndWriteNode



8143
8144
8145
# File 'lib/prism/node.rb', line 8143

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value)
  GlobalVariableAndWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value)
end

#deconstruct_keys(keys) ⇒ Object

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



8151
8152
8153
# File 'lib/prism/node.rb', line 8151

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

#desugarObject

:nodoc:



201
202
203
# File 'lib/prism/desugar_compiler.rb', line 201

def desugar # :nodoc:
  DesugarAndWriteNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
end

#each_child_node {|value| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



8126
8127
8128
8129
8130
# File 'lib/prism/node.rb', line 8126

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield value
end

#inspectObject

def inspect -> String



8193
8194
8195
# File 'lib/prism/node.rb', line 8193

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



8159
8160
8161
8162
8163
# File 'lib/prism/node.rb', line 8159

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

#operatorObject

def operator: () -> String



8188
8189
8190
# File 'lib/prism/node.rb', line 8188

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



8172
8173
8174
8175
8176
# File 'lib/prism/node.rb', line 8172

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

#save_name_loc(repository) ⇒ Object

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



8167
8168
8169
# File 'lib/prism/node.rb', line 8167

def save_name_loc(repository)
  repository.enter(node_id, :name_loc)
end

#save_operator_loc(repository) ⇒ Object

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



8180
8181
8182
# File 'lib/prism/node.rb', line 8180

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

#typeObject

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



8198
8199
8200
# File 'lib/prism/node.rb', line 8198

def type
  :global_variable_and_write_node
end