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.



3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
# File 'lib/prism/node.rb', line 3955

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



4000
4001
4002
# File 'lib/prism/node.rb', line 4000

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



4017
4018
4019
# File 'lib/prism/node.rb', line 4017

def value
  @value
end

Class Method Details

.typeObject

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



4035
4036
4037
# File 'lib/prism/node.rb', line 4035

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.



4041
4042
4043
4044
4045
4046
4047
# File 'lib/prism/node.rb', line 4041

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



3967
3968
3969
# File 'lib/prism/node.rb', line 3967

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

#child_nodesObject Also known as: deconstruct

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



3972
3973
3974
# File 'lib/prism/node.rb', line 3972

def child_nodes
  [value]
end

#comment_targetsObject

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



3982
3983
3984
# File 'lib/prism/node.rb', line 3982

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



3977
3978
3979
# File 'lib/prism/node.rb', line 3977

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



3987
3988
3989
# File 'lib/prism/node.rb', line 3987

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 }



3995
3996
3997
# File 'lib/prism/node.rb', line 3995

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



4025
4026
4027
# File 'lib/prism/node.rb', line 4025

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



4003
4004
4005
4006
4007
# File 'lib/prism/node.rb', line 4003

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



4020
4021
4022
# File 'lib/prism/node.rb', line 4020

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



4010
4011
4012
4013
4014
# File 'lib/prism/node.rb', line 4010

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



4030
4031
4032
# File 'lib/prism/node.rb', line 4030

def type
  :constant_and_write_node
end