Class: Prism::InstanceVariableOperatorWriteNode

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 an instance 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) ⇒ InstanceVariableOperatorWriteNode

Initialize a new InstanceVariableOperatorWriteNode node.



8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
# File 'lib/prism/node.rb', line 8792

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



8858
8859
8860
# File 'lib/prism/node.rb', line 8858

def binary_operator
  @binary_operator
end

#nameObject (readonly)

attr_reader name: Symbol



8838
8839
8840
# File 'lib/prism/node.rb', line 8838

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



8855
8856
8857
# File 'lib/prism/node.rb', line 8855

def value
  @value
end

Class Method Details

.typeObject

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



8871
8872
8873
# File 'lib/prism/node.rb', line 8871

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



8877
8878
8879
8880
8881
8882
8883
8884
# File 'lib/prism/node.rb', line 8877

def ===(other)
  other.is_a?(InstanceVariableOperatorWriteNode) &&
    (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



8805
8806
8807
# File 'lib/prism/node.rb', line 8805

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

#binary_operator_locObject

attr_reader binary_operator_loc: Location



8848
8849
8850
8851
8852
# File 'lib/prism/node.rb', line 8848

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]



8810
8811
8812
# File 'lib/prism/node.rb', line 8810

def child_nodes
  [value]
end

#comment_targetsObject

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



8820
8821
8822
# File 'lib/prism/node.rb', line 8820

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



8815
8816
8817
# File 'lib/prism/node.rb', line 8815

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) -> InstanceVariableOperatorWriteNode



8825
8826
8827
# File 'lib/prism/node.rb', line 8825

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)
  InstanceVariableOperatorWriteNode.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 }



8833
8834
8835
# File 'lib/prism/node.rb', line 8833

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:



230
231
232
# File 'lib/prism/desugar_compiler.rb', line 230

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

#inspectObject

def inspect -> String



8861
8862
8863
# File 'lib/prism/node.rb', line 8861

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



8841
8842
8843
8844
8845
# File 'lib/prism/node.rb', line 8841

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.



435
436
437
438
# File 'lib/prism/node_ext.rb', line 435

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.



442
443
444
445
# File 'lib/prism/node_ext.rb', line 442

def operator_loc
  deprecated("binary_operator_loc")
  binary_operator_loc
end

#typeObject

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



8866
8867
8868
# File 'lib/prism/node.rb', line 8866

def type
  :instance_variable_operator_write_node
end