Class: Prism::ConstantAndWriteNode

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

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) ⇒ ConstantAndWriteNode

Initialize a new ConstantAndWriteNode node.



4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
# File 'lib/prism/node.rb', line 4608

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



4653
4654
4655
# File 'lib/prism/node.rb', line 4653

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



4682
4683
4684
# File 'lib/prism/node.rb', line 4682

def value
  @value
end

Class Method Details

.typeObject

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



4700
4701
4702
# File 'lib/prism/node.rb', line 4700

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



4706
4707
4708
4709
4710
4711
4712
# File 'lib/prism/node.rb', line 4706

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



4620
4621
4622
# File 'lib/prism/node.rb', line 4620

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

#child_nodesObject Also known as: deconstruct

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



4625
4626
4627
# File 'lib/prism/node.rb', line 4625

def child_nodes
  [value]
end

#comment_targetsObject

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



4635
4636
4637
# File 'lib/prism/node.rb', line 4635

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



4630
4631
4632
# File 'lib/prism/node.rb', line 4630

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



4640
4641
4642
# File 'lib/prism/node.rb', line 4640

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



4648
4649
4650
# File 'lib/prism/node.rb', line 4648

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:



182
183
184
# File 'lib/prism/desugar_compiler.rb', line 182

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

#inspectObject

def inspect -> String



4690
4691
4692
# File 'lib/prism/node.rb', line 4690

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



4656
4657
4658
4659
4660
# File 'lib/prism/node.rb', line 4656

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



4685
4686
4687
# File 'lib/prism/node.rb', line 4685

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



4669
4670
4671
4672
4673
# File 'lib/prism/node.rb', line 4669

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.



4664
4665
4666
# File 'lib/prism/node.rb', line 4664

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.



4677
4678
4679
# File 'lib/prism/node.rb', line 4677

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

#typeObject

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



4695
4696
4697
# File 'lib/prism/node.rb', line 4695

def type
  :constant_and_write_node
end