Class: Prism::InstanceVariableAndWriteNode

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

Initialize a new InstanceVariableAndWriteNode node.



9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
# File 'lib/prism/node.rb', line 9872

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



9917
9918
9919
# File 'lib/prism/node.rb', line 9917

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



9946
9947
9948
# File 'lib/prism/node.rb', line 9946

def value
  @value
end

Class Method Details

.typeObject

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



9964
9965
9966
# File 'lib/prism/node.rb', line 9964

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



9970
9971
9972
9973
9974
9975
9976
# File 'lib/prism/node.rb', line 9970

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



9884
9885
9886
# File 'lib/prism/node.rb', line 9884

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



9889
9890
9891
# File 'lib/prism/node.rb', line 9889

def child_nodes
  [value]
end

#comment_targetsObject

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



9899
9900
9901
# File 'lib/prism/node.rb', line 9899

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



9894
9895
9896
# File 'lib/prism/node.rb', line 9894

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



9904
9905
9906
# File 'lib/prism/node.rb', line 9904

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



9912
9913
9914
# File 'lib/prism/node.rb', line 9912

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:



219
220
221
# File 'lib/prism/desugar_compiler.rb', line 219

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

#inspectObject

def inspect -> String



9954
9955
9956
# File 'lib/prism/node.rb', line 9954

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



9920
9921
9922
9923
9924
# File 'lib/prism/node.rb', line 9920

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



9949
9950
9951
# File 'lib/prism/node.rb', line 9949

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



9933
9934
9935
9936
9937
# File 'lib/prism/node.rb', line 9933

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.



9928
9929
9930
# File 'lib/prism/node.rb', line 9928

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.



9941
9942
9943
# File 'lib/prism/node.rb', line 9941

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

#typeObject

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



9959
9960
9961
# File 'lib/prism/node.rb', line 9959

def type
  :instance_variable_and_write_node
end