Class: Prism::GlobalVariableOperatorWriteNode

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

Overview

Represents assigning to a global variable using an operator that isn’t ‘=`.

$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, binary_operator_loc, value, binary_operator) ⇒ GlobalVariableOperatorWriteNode

Initialize a new GlobalVariableOperatorWriteNode node.



6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
# File 'lib/prism/node.rb', line 6725

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

Instance Attribute Details

#binary_operatorObject (readonly)

attr_reader binary_operator: Symbol



6791
6792
6793
# File 'lib/prism/node.rb', line 6791

def binary_operator
  @binary_operator
end

#nameObject (readonly)

attr_reader name: Symbol



6771
6772
6773
# File 'lib/prism/node.rb', line 6771

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



6788
6789
6790
# File 'lib/prism/node.rb', line 6788

def value
  @value
end

Class Method Details

.typeObject

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



6804
6805
6806
# File 'lib/prism/node.rb', line 6804

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



6810
6811
6812
6813
6814
6815
6816
6817
# File 'lib/prism/node.rb', line 6810

def ===(other)
  other.is_a?(GlobalVariableOperatorWriteNode) &&
    (name === other.name) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
    (value === other.value) &&
    (binary_operator === other.binary_operator)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



6738
6739
6740
# File 'lib/prism/node.rb', line 6738

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

#binary_operator_locObject

attr_reader binary_operator_loc: Location



6781
6782
6783
6784
6785
# File 'lib/prism/node.rb', line 6781

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

#child_nodesObject Also known as: deconstruct

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



6743
6744
6745
# File 'lib/prism/node.rb', line 6743

def child_nodes
  [value]
end

#comment_targetsObject

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



6753
6754
6755
# File 'lib/prism/node.rb', line 6753

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



6748
6749
6750
# File 'lib/prism/node.rb', line 6748

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, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator) ⇒ Object

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



6758
6759
6760
# File 'lib/prism/node.rb', line 6758

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator)
  GlobalVariableOperatorWriteNode.new(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
end

#deconstruct_keys(keys) ⇒ Object

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



6766
6767
6768
# File 'lib/prism/node.rb', line 6766

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

#desugarObject

:nodoc:



212
213
214
# File 'lib/prism/desugar_compiler.rb', line 212

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

#inspectObject

def inspect -> String



6794
6795
6796
# File 'lib/prism/node.rb', line 6794

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



6774
6775
6776
6777
6778
# File 'lib/prism/node.rb', line 6774

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

#operatorObject

Returns the binary operator used to modify the receiver. This method is deprecated in favor of #binary_operator.



403
404
405
406
# File 'lib/prism/node_ext.rb', line 403

def operator
  deprecated("binary_operator")
  binary_operator
end

#operator_locObject

Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of #binary_operator_loc.



410
411
412
413
# File 'lib/prism/node_ext.rb', line 410

def operator_loc
  deprecated("binary_operator_loc")
  binary_operator_loc
end

#typeObject

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



6799
6800
6801
# File 'lib/prism/node.rb', line 6799

def type
  :global_variable_operator_write_node
end