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.



8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
# File 'lib/prism/node.rb', line 8691

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



8736
8737
8738
# File 'lib/prism/node.rb', line 8736

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



8753
8754
8755
# File 'lib/prism/node.rb', line 8753

def value
  @value
end

Class Method Details

.typeObject

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



8771
8772
8773
# File 'lib/prism/node.rb', line 8771

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.



8777
8778
8779
8780
8781
8782
8783
# File 'lib/prism/node.rb', line 8777

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



8703
8704
8705
# File 'lib/prism/node.rb', line 8703

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

#child_nodesObject Also known as: deconstruct

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



8708
8709
8710
# File 'lib/prism/node.rb', line 8708

def child_nodes
  [value]
end

#comment_targetsObject

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



8718
8719
8720
# File 'lib/prism/node.rb', line 8718

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



8713
8714
8715
# File 'lib/prism/node.rb', line 8713

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



8723
8724
8725
# File 'lib/prism/node.rb', line 8723

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 }



8731
8732
8733
# File 'lib/prism/node.rb', line 8731

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:



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

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

#inspectObject

def inspect -> String



8761
8762
8763
# File 'lib/prism/node.rb', line 8761

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



8739
8740
8741
8742
8743
# File 'lib/prism/node.rb', line 8739

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



8756
8757
8758
# File 'lib/prism/node.rb', line 8756

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



8746
8747
8748
8749
8750
# File 'lib/prism/node.rb', line 8746

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

#typeObject

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



8766
8767
8768
# File 'lib/prism/node.rb', line 8766

def type
  :instance_variable_and_write_node
end