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.



11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
# File 'lib/prism/node.rb', line 11683

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



11761
11762
11763
# File 'lib/prism/node.rb', line 11761

def depth
  @depth
end

#nameObject (readonly)

attr_reader name: Symbol



11758
11759
11760
# File 'lib/prism/node.rb', line 11758

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



11755
11756
11757
# File 'lib/prism/node.rb', line 11755

def value
  @value
end

Class Method Details

.typeObject

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



11779
11780
11781
# File 'lib/prism/node.rb', line 11779

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.



11785
11786
11787
11788
11789
11790
11791
11792
# File 'lib/prism/node.rb', line 11785

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



11696
11697
11698
# File 'lib/prism/node.rb', line 11696

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

#child_nodesObject Also known as: deconstruct

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



11701
11702
11703
# File 'lib/prism/node.rb', line 11701

def child_nodes
  [value]
end

#comment_targetsObject

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



11711
11712
11713
# File 'lib/prism/node.rb', line 11711

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



11706
11707
11708
# File 'lib/prism/node.rb', line 11706

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



11716
11717
11718
# File 'lib/prism/node.rb', line 11716

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 }



11724
11725
11726
# File 'lib/prism/node.rb', line 11724

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



11769
11770
11771
# File 'lib/prism/node.rb', line 11769

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



11729
11730
11731
11732
11733
# File 'lib/prism/node.rb', line 11729

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



11764
11765
11766
# File 'lib/prism/node.rb', line 11764

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



11742
11743
11744
11745
11746
# File 'lib/prism/node.rb', line 11742

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.



11737
11738
11739
# File 'lib/prism/node.rb', line 11737

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.



11750
11751
11752
# File 'lib/prism/node.rb', line 11750

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

#typeObject

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



11774
11775
11776
# File 'lib/prism/node.rb', line 11774

def type
  :local_variable_and_write_node
end