Class: Prism::GlobalVariableOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::GlobalVariableOrWriteNode
- Defined in:
- lib/prism/node.rb,
lib/prism/desugar_compiler.rb,
sig/generated/prism/node.rbs,
sig/generated/prism/desugar_compiler.rbs,
ext/prism/api_node.c
Overview
Represents the use of the ||= operator for assignment to a global variable.
$target ||= value
^^^^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :global_variable_or_write_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#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) ⇒ GlobalVariableOrWriteNode
:call-seq: copy(**fields) -> GlobalVariableOrWriteNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#desugar ⇒ node
: () -> node.
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ GlobalVariableOrWriteNode
constructor
Initialize a new GlobalVariableOrWriteNode node.
-
#inspect ⇒ String
: () -> String.
-
#name ⇒ Symbol
:call-seq: name -> Symbol.
-
#name_loc ⇒ Location
:category: Locations :call-seq: name_loc -> Location.
-
#operator ⇒ String
:call-seq: operator -> String.
-
#operator_loc ⇒ Location
:category: Locations :call-seq: operator_loc -> Location.
-
#save_name_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the name_loc location using the given saved source so that it can be retrieved later.
-
#save_operator_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :global_variable_or_write_node
See
Node#type. -
#value ⇒ Prism::node
:call-seq: value -> Node.
Constructor Details
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ GlobalVariableOrWriteNode
Initialize a new GlobalVariableOrWriteNode node.
: (Source source, Integer node_id, Location location, Integer flags, Symbol name, Location name_loc, Location operator_loc, Prism::node value) -> void
14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 |
# File 'lib/prism/node.rb', line 14365 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 |
Class Method Details
.type ⇒ :global_variable_or_write_node
See Node.type.
: () -> :global_variable_or_write_node
14457 14458 14459 |
# File 'lib/prism/node.rb', line 14457 def self.type :global_variable_or_write_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
14547 14548 14549 14550 14551 14552 14553 |
# File 'lib/prism/node.rb', line 14547 def ===(other) # :nodoc: other.is_a?(GlobalVariableOrWriteNode) && (name === other.name) && (name_loc.nil? == other.name_loc.nil?) && (operator_loc.nil? == other.operator_loc.nil?) && (value === other.value) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
14390 14391 14392 |
# File 'lib/prism/node.rb', line 14390 def accept(visitor) visitor.visit_global_variable_or_write_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
14397 14398 14399 |
# File 'lib/prism/node.rb', line 14397 def child_nodes [value] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
14414 14415 14416 |
# File 'lib/prism/node.rb', line 14414 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) ⇒ GlobalVariableOrWriteNode
:call-seq:
copy(**fields) -> GlobalVariableOrWriteNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?operator_loc: Location, ?value: Prism::node) -> GlobalVariableOrWriteNode
14424 14425 14426 |
# File 'lib/prism/node.rb', line 14424 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) GlobalVariableOrWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
14431 14432 14433 14434 14435 14436 14437 14438 14439 14440 14441 14442 14443 14444 14445 |
# File 'lib/prism/node.rb', line 14431 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location name name_loc operator_loc value operator]).each_with_object( {} #: Hash[Symbol, untyped] ) do |key, deconstructed| case key when :node_id then deconstructed[:node_id] = self.node_id when :location then deconstructed[:location] = self.location when :name then deconstructed[:name] = self.name when :name_loc then deconstructed[:name_loc] = self.name_loc when :operator_loc then deconstructed[:operator_loc] = self.operator_loc when :value then deconstructed[:value] = self.value when :operator then deconstructed[:operator] = self.operator end end end |
#desugar ⇒ node
: () -> node
241 242 243 |
# File 'lib/prism/desugar_compiler.rb', line 241 def desugar # :nodoc: DesugarOrWriteDefinedNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
14405 14406 14407 14408 14409 |
# File 'lib/prism/node.rb', line 14405 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield value end |
#inspect ⇒ String
: () -> String
14462 14463 14464 |
# File 'lib/prism/node.rb', line 14462 def inspect # :nodoc: InspectVisitor.compose(self) end |
#name ⇒ Symbol
:call-seq:
name -> Symbol
Returns the name attribute.
: () -> Symbol
14474 14475 14476 |
# File 'lib/prism/node.rb', line 14474 def name @name end |
#name_loc ⇒ Location
:category: Locations :call-seq:
name_loc -> Location
Returns the Location represented by name_loc.
: () -> Location
14485 14486 14487 14488 14489 |
# File 'lib/prism/node.rb', line 14485 def name_loc location = @name_loc return location if location.is_a?(Location) @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
14540 14541 14542 |
# File 'lib/prism/node.rb', line 14540 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
Returns the Location represented by operator_loc.
: () -> Location
14507 14508 14509 14510 14511 |
# File 'lib/prism/node.rb', line 14507 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) ⇒ Relocation::Entry
:category: Repository Save the name_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
14496 14497 14498 |
# File 'lib/prism/node.rb', line 14496 def save_name_loc(repository) repository.enter(node_id, :name_loc) end |
#save_operator_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the operator_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
14518 14519 14520 |
# File 'lib/prism/node.rb', line 14518 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ :global_variable_or_write_node
See Node#type.
: () -> :global_variable_or_write_node
14450 14451 14452 |
# File 'lib/prism/node.rb', line 14450 def type :global_variable_or_write_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
Returns the value attribute.
: () -> Prism::node
14528 14529 14530 |
# File 'lib/prism/node.rb', line 14528 def value @value end |