Class: Prism::LocalVariableAndWriteNode

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 a local variable.

target &&= value
^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name_loc, operator_loc, value, name, depth) ⇒ LocalVariableAndWriteNode

Initialize a new LocalVariableAndWriteNode node.



10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
# File 'lib/prism/node.rb', line 10466

def initialize(source, node_id, location, flags, name_loc, operator_loc, value, name, depth)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @name_loc = name_loc
  @operator_loc = operator_loc
  @value = value
  @name = name
  @depth = depth
end

Instance Attribute Details

#depthObject (readonly)

attr_reader depth: Integer



10532
10533
10534
# File 'lib/prism/node.rb', line 10532

def depth
  @depth
end

#nameObject (readonly)

attr_reader name: Symbol



10529
10530
10531
# File 'lib/prism/node.rb', line 10529

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



10526
10527
10528
# File 'lib/prism/node.rb', line 10526

def value
  @value
end

Class Method Details

.typeObject

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



10550
10551
10552
# File 'lib/prism/node.rb', line 10550

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



10556
10557
10558
10559
10560
10561
10562
10563
# File 'lib/prism/node.rb', line 10556

def ===(other)
  other.is_a?(LocalVariableAndWriteNode) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (operator_loc.nil? == other.operator_loc.nil?) &&
    (value === other.value) &&
    (name === other.name) &&
    (depth === other.depth)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



10479
10480
10481
# File 'lib/prism/node.rb', line 10479

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

#child_nodesObject Also known as: deconstruct

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



10484
10485
10486
# File 'lib/prism/node.rb', line 10484

def child_nodes
  [value]
end

#comment_targetsObject

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



10494
10495
10496
# File 'lib/prism/node.rb', line 10494

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



10489
10490
10491
# File 'lib/prism/node.rb', line 10489

def compact_child_nodes
  [value]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value, name: self.name, depth: self.depth) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node, ?name: Symbol, ?depth: Integer) -> LocalVariableAndWriteNode



10499
10500
10501
# File 'lib/prism/node.rb', line 10499

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name_loc: self.name_loc, operator_loc: self.operator_loc, value: self.value, name: self.name, depth: self.depth)
  LocalVariableAndWriteNode.new(source, node_id, location, flags, name_loc, operator_loc, value, name, depth)
end

#deconstruct_keys(keys) ⇒ Object

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



10507
10508
10509
# File 'lib/prism/node.rb', line 10507

def deconstruct_keys(keys)
  { node_id: node_id, location: location, name_loc: name_loc, operator_loc: operator_loc, value: value, name: name, depth: depth }
end

#desugarObject

:nodoc:



236
237
238
# File 'lib/prism/desugar_compiler.rb', line 236

def desugar # :nodoc:
  DesugarAndWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
end

#inspectObject

def inspect -> String



10540
10541
10542
# File 'lib/prism/node.rb', line 10540

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



10512
10513
10514
10515
10516
# File 'lib/prism/node.rb', line 10512

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



10535
10536
10537
# File 'lib/prism/node.rb', line 10535

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



10519
10520
10521
10522
10523
# File 'lib/prism/node.rb', line 10519

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



10545
10546
10547
# File 'lib/prism/node.rb', line 10545

def type
  :local_variable_and_write_node
end