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.



6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
# File 'lib/prism/node.rb', line 6762

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



6828
6829
6830
# File 'lib/prism/node.rb', line 6828

def binary_operator
  @binary_operator
end

#nameObject (readonly)

attr_reader name: Symbol



6808
6809
6810
# File 'lib/prism/node.rb', line 6808

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



6825
6826
6827
# File 'lib/prism/node.rb', line 6825

def value
  @value
end

Class Method Details

.typeObject

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



6841
6842
6843
# File 'lib/prism/node.rb', line 6841

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.



6847
6848
6849
6850
6851
6852
6853
6854
# File 'lib/prism/node.rb', line 6847

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



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

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

#binary_operator_locObject

attr_reader binary_operator_loc: Location



6818
6819
6820
6821
6822
# File 'lib/prism/node.rb', line 6818

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]



6780
6781
6782
# File 'lib/prism/node.rb', line 6780

def child_nodes
  [value]
end

#comment_targetsObject

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



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

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



6785
6786
6787
# File 'lib/prism/node.rb', line 6785

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



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

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 }



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

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



6831
6832
6833
# File 'lib/prism/node.rb', line 6831

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



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

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



6836
6837
6838
# File 'lib/prism/node.rb', line 6836

def type
  :global_variable_operator_write_node
end