Class: Prism::ConstantOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ConstantOrWriteNode
- 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
-
#name ⇒ Object
readonly
attr_reader name: Symbol.
-
#value ⇒ Object
readonly
attr_reader value: Prism::node.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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) -> ConstantOrWriteNode.
-
#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 }.
-
#desugar ⇒ Object
:nodoc:.
-
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ ConstantOrWriteNode
constructor
Initialize a new ConstantOrWriteNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#name_loc ⇒ Object
attr_reader name_loc: Location.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ ConstantOrWriteNode
Initialize a new ConstantOrWriteNode node.
4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 |
# File 'lib/prism/node.rb', line 4157 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
#name ⇒ Object (readonly)
attr_reader name: Symbol
4202 4203 4204 |
# File 'lib/prism/node.rb', line 4202 def name @name end |
#value ⇒ Object (readonly)
attr_reader value: Prism::node
4219 4220 4221 |
# File 'lib/prism/node.rb', line 4219 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
4237 4238 4239 |
# File 'lib/prism/node.rb', line 4237 def self.type :constant_or_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.
4243 4244 4245 4246 4247 4248 4249 |
# File 'lib/prism/node.rb', line 4243 def ===(other) other.is_a?(ConstantOrWriteNode) && (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
4169 4170 4171 |
# File 'lib/prism/node.rb', line 4169 def accept(visitor) visitor.visit_constant_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
4174 4175 4176 |
# File 'lib/prism/node.rb', line 4174 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
4184 4185 4186 |
# File 'lib/prism/node.rb', line 4184 def comment_targets [name_loc, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
4179 4180 4181 |
# File 'lib/prism/node.rb', line 4179 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) -> ConstantOrWriteNode
4189 4190 4191 |
# File 'lib/prism/node.rb', line 4189 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) ConstantOrWriteNode.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 }
4197 4198 4199 |
# File 'lib/prism/node.rb', line 4197 def deconstruct_keys(keys) { node_id: node_id, location: location, name: name, name_loc: name_loc, operator_loc: operator_loc, value: value } end |
#desugar ⇒ Object
:nodoc:
188 189 190 |
# File 'lib/prism/desugar_compiler.rb', line 188 def desugar # :nodoc: DesugarOrWriteDefinedNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile end |
#inspect ⇒ Object
def inspect -> String
4227 4228 4229 |
# File 'lib/prism/node.rb', line 4227 def inspect InspectVisitor.compose(self) end |
#name_loc ⇒ Object
attr_reader name_loc: Location
4205 4206 4207 4208 4209 |
# File 'lib/prism/node.rb', line 4205 def name_loc location = @name_loc return location if location.is_a?(Location) @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ Object
def operator: () -> String
4222 4223 4224 |
# File 'lib/prism/node.rb', line 4222 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
4212 4213 4214 4215 4216 |
# File 'lib/prism/node.rb', line 4212 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
4232 4233 4234 |
# File 'lib/prism/node.rb', line 4232 def type :constant_or_write_node end |