Class: Prism::GlobalVariableAndWriteNode

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 global 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) ⇒ GlobalVariableAndWriteNode

Initialize a new GlobalVariableAndWriteNode node.



7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
# File 'lib/prism/node.rb', line 7620

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



7665
7666
7667
# File 'lib/prism/node.rb', line 7665

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



7694
7695
7696
# File 'lib/prism/node.rb', line 7694

def value
  @value
end

Class Method Details

.typeObject

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



7712
7713
7714
# File 'lib/prism/node.rb', line 7712

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



7718
7719
7720
7721
7722
7723
7724
# File 'lib/prism/node.rb', line 7718

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



7632
7633
7634
# File 'lib/prism/node.rb', line 7632

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



7637
7638
7639
# File 'lib/prism/node.rb', line 7637

def child_nodes
  [value]
end

#comment_targetsObject

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



7647
7648
7649
# File 'lib/prism/node.rb', line 7647

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



7642
7643
7644
# File 'lib/prism/node.rb', line 7642

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



7652
7653
7654
# File 'lib/prism/node.rb', line 7652

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



7660
7661
7662
# File 'lib/prism/node.rb', line 7660

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:



201
202
203
# File 'lib/prism/desugar_compiler.rb', line 201

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

#inspectObject

def inspect -> String



7702
7703
7704
# File 'lib/prism/node.rb', line 7702

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



7668
7669
7670
7671
7672
# File 'lib/prism/node.rb', line 7668

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



7697
7698
7699
# File 'lib/prism/node.rb', line 7697

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



7681
7682
7683
7684
7685
# File 'lib/prism/node.rb', line 7681

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.



7676
7677
7678
# File 'lib/prism/node.rb', line 7676

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.



7689
7690
7691
# File 'lib/prism/node.rb', line 7689

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

#typeObject

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



7707
7708
7709
# File 'lib/prism/node.rb', line 7707

def type
  :global_variable_and_write_node
end