Class: Prism::ClassVariableAndWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ClassVariableAndWriteNode
- 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 class variable.
@@target &&= value
^^^^^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :class_variable_and_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) ⇒ ClassVariableAndWriteNode
:call-seq: copy(**fields) -> ClassVariableAndWriteNode.
-
#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) ⇒ ClassVariableAndWriteNode
constructor
Initialize a new ClassVariableAndWriteNode 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 ⇒ :class_variable_and_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) ⇒ ClassVariableAndWriteNode
Initialize a new ClassVariableAndWriteNode node.
: (Source source, Integer node_id, Location location, Integer flags, Symbol name, Location name_loc, Location operator_loc, Prism::node value) -> void
7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 |
# File 'lib/prism/node.rb', line 7230 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 ⇒ :class_variable_and_write_node
See Node.type.
: () -> :class_variable_and_write_node
7322 7323 7324 |
# File 'lib/prism/node.rb', line 7322 def self.type :class_variable_and_write_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
7440 7441 7442 7443 7444 7445 7446 |
# File 'lib/prism/node.rb', line 7440 def ===(other) # :nodoc: other.is_a?(ClassVariableAndWriteNode) && (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
7255 7256 7257 |
# File 'lib/prism/node.rb', line 7255 def accept(visitor) visitor.visit_class_variable_and_write_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
7262 7263 7264 |
# File 'lib/prism/node.rb', line 7262 def child_nodes [value] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
7279 7280 7281 |
# File 'lib/prism/node.rb', line 7279 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) ⇒ ClassVariableAndWriteNode
:call-seq:
copy(**fields) -> ClassVariableAndWriteNode
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) -> ClassVariableAndWriteNode
7289 7290 7291 |
# File 'lib/prism/node.rb', line 7289 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) ClassVariableAndWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 |
# File 'lib/prism/node.rb', line 7296 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
192 193 194 |
# File 'lib/prism/desugar_compiler.rb', line 192 def desugar # :nodoc: DesugarAndWriteNode.new(self, source, :class_variable_read_node, :class_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
7270 7271 7272 7273 7274 |
# File 'lib/prism/node.rb', line 7270 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield value end |
#inspect ⇒ String
: () -> String
7327 7328 7329 |
# File 'lib/prism/node.rb', line 7327 def inspect # :nodoc: InspectVisitor.compose(self) end |
#name ⇒ Symbol
:call-seq:
name -> Symbol
The name of the class variable, which is a @@ followed by an identifier.
@@target &&= value # name `:@@target`
^^^^^^^^
: () -> Symbol
7346 7347 7348 |
# File 'lib/prism/node.rb', line 7346 def name @name end |
#name_loc ⇒ Location
:category: Locations :call-seq:
name_loc -> Location
Represents the Location of the variable name.
@@target &&= value
^^^^^^^^
: () -> Location
7364 7365 7366 7367 7368 |
# File 'lib/prism/node.rb', line 7364 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
7433 7434 7435 |
# File 'lib/prism/node.rb', line 7433 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
Represents the Location of the &&= operator.
@@target &&= value
^^^
: () -> Location
7393 7394 7395 7396 7397 |
# File 'lib/prism/node.rb', line 7393 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
7375 7376 7377 |
# File 'lib/prism/node.rb', line 7375 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
7404 7405 7406 |
# File 'lib/prism/node.rb', line 7404 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ :class_variable_and_write_node
See Node#type.
: () -> :class_variable_and_write_node
7315 7316 7317 |
# File 'lib/prism/node.rb', line 7315 def type :class_variable_and_write_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
Represents the value being assigned. This can be any non-void expression.
@@target &&= value
^^^^^
: () -> Prism::node
7421 7422 7423 |
# File 'lib/prism/node.rb', line 7421 def value @value end |