Class: Prism::ConstantOperatorWriteNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
lib/prism/node_ext.rb,
lib/prism/desugar_compiler.rb,
ext/prism/api_node.c

Overview

Represents assigning to a constant using an operator that isn’t ‘=`.

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, binary_operator_loc, value, binary_operator) ⇒ ConstantOperatorWriteNode

Initialize a new ConstantOperatorWriteNode node.



4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
# File 'lib/prism/node.rb', line 4019

def initialize(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @name = name
  @name_loc = name_loc
  @binary_operator_loc = binary_operator_loc
  @value = value
  @binary_operator = binary_operator
end

Instance Attribute Details

#binary_operatorObject (readonly)

attr_reader binary_operator: Symbol



4085
4086
4087
# File 'lib/prism/node.rb', line 4085

def binary_operator
  @binary_operator
end

#nameObject (readonly)

attr_reader name: Symbol



4065
4066
4067
# File 'lib/prism/node.rb', line 4065

def name
  @name
end

#valueObject (readonly)

attr_reader value: Prism::node



4082
4083
4084
# File 'lib/prism/node.rb', line 4082

def value
  @value
end

Class Method Details

.typeObject

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



4098
4099
4100
# File 'lib/prism/node.rb', line 4098

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



4104
4105
4106
4107
4108
4109
4110
4111
# File 'lib/prism/node.rb', line 4104

def ===(other)
  other.is_a?(ConstantOperatorWriteNode) &&
    (name === other.name) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (binary_operator_loc.nil? == other.binary_operator_loc.nil?) &&
    (value === other.value) &&
    (binary_operator === other.binary_operator)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



4032
4033
4034
# File 'lib/prism/node.rb', line 4032

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

#binary_operator_locObject

attr_reader binary_operator_loc: Location



4075
4076
4077
4078
4079
# File 'lib/prism/node.rb', line 4075

def binary_operator_loc
  location = @binary_operator_loc
  return location if location.is_a?(Location)
  @binary_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#child_nodesObject Also known as: deconstruct

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



4037
4038
4039
# File 'lib/prism/node.rb', line 4037

def child_nodes
  [value]
end

#comment_targetsObject

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



4047
4048
4049
# File 'lib/prism/node.rb', line 4047

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



4042
4043
4044
# File 'lib/prism/node.rb', line 4042

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, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?binary_operator_loc: Location, ?value: Prism::node, ?binary_operator: Symbol) -> ConstantOperatorWriteNode



4052
4053
4054
# File 'lib/prism/node.rb', line 4052

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, binary_operator_loc: self.binary_operator_loc, value: self.value, binary_operator: self.binary_operator)
  ConstantOperatorWriteNode.new(source, node_id, location, flags, name, name_loc, binary_operator_loc, value, binary_operator)
end

#deconstruct_keys(keys) ⇒ Object

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



4060
4061
4062
# File 'lib/prism/node.rb', line 4060

def deconstruct_keys(keys)
  { node_id: node_id, location: location, name: name, name_loc: name_loc, binary_operator_loc: binary_operator_loc, value: value, binary_operator: binary_operator }
end

#desugarObject

:nodoc:



194
195
196
# File 'lib/prism/desugar_compiler.rb', line 194

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

#inspectObject

def inspect -> String



4088
4089
4090
# File 'lib/prism/node.rb', line 4088

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location



4068
4069
4070
4071
4072
# File 'lib/prism/node.rb', line 4068

def name_loc
  location = @name_loc
  return location if location.is_a?(Location)
  @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#operatorObject

Returns the binary operator used to modify the receiver. This method is deprecated in favor of #binary_operator.



371
372
373
374
# File 'lib/prism/node_ext.rb', line 371

def operator
  deprecated("binary_operator")
  binary_operator
end

#operator_locObject

Returns the location of the binary operator used to modify the receiver. This method is deprecated in favor of #binary_operator_loc.



378
379
380
381
# File 'lib/prism/node_ext.rb', line 378

def operator_loc
  deprecated("binary_operator_loc")
  binary_operator_loc
end

#typeObject

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



4093
4094
4095
# File 'lib/prism/node.rb', line 4093

def type
  :constant_operator_write_node
end