Class: Prism::InstanceVariableOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::InstanceVariableOrWriteNode
- 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 an instance variable.
^^^^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :instance_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) ⇒ InstanceVariableOrWriteNode
:call-seq: copy(**fields) -> InstanceVariableOrWriteNode.
-
#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) ⇒ InstanceVariableOrWriteNode
constructor
Initialize a new InstanceVariableOrWriteNode 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 ⇒ :instance_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) ⇒ InstanceVariableOrWriteNode
Initialize a new InstanceVariableOrWriteNode node.
: (Source source, Integer node_id, Location location, Integer flags, Symbol name, Location name_loc, Location operator_loc, Prism::node value) -> void
18411 18412 18413 18414 18415 18416 18417 18418 18419 18420 |
# File 'lib/prism/node.rb', line 18411 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 ⇒ :instance_variable_or_write_node
See Node.type.
: () -> :instance_variable_or_write_node
18503 18504 18505 |
# File 'lib/prism/node.rb', line 18503 def self.type :instance_variable_or_write_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
18593 18594 18595 18596 18597 18598 18599 |
# File 'lib/prism/node.rb', line 18593 def ===(other) # :nodoc: other.is_a?(InstanceVariableOrWriteNode) && (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
18436 18437 18438 |
# File 'lib/prism/node.rb', line 18436 def accept(visitor) visitor.visit_instance_variable_or_write_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
18443 18444 18445 |
# File 'lib/prism/node.rb', line 18443 def child_nodes [value] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
18460 18461 18462 |
# File 'lib/prism/node.rb', line 18460 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) ⇒ InstanceVariableOrWriteNode
:call-seq:
copy(**fields) -> InstanceVariableOrWriteNode
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) -> InstanceVariableOrWriteNode
18470 18471 18472 |
# File 'lib/prism/node.rb', line 18470 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) InstanceVariableOrWriteNode.new(source, node_id, location, flags, name, name_loc, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
18477 18478 18479 18480 18481 18482 18483 18484 18485 18486 18487 18488 18489 18490 18491 |
# File 'lib/prism/node.rb', line 18477 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
262 263 264 |
# File 'lib/prism/desugar_compiler.rb', line 262 def desugar # :nodoc: DesugarOrWriteNode.new(self, source, :instance_variable_read_node, :instance_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
18451 18452 18453 18454 18455 |
# File 'lib/prism/node.rb', line 18451 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield value end |
#inspect ⇒ String
: () -> String
18508 18509 18510 |
# File 'lib/prism/node.rb', line 18508 def inspect # :nodoc: InspectVisitor.compose(self) end |
#name ⇒ Symbol
:call-seq:
name -> Symbol
Returns the name attribute.
: () -> Symbol
18520 18521 18522 |
# File 'lib/prism/node.rb', line 18520 def name @name end |
#name_loc ⇒ Location
:category: Locations :call-seq:
name_loc -> Location
Returns the Location represented by name_loc.
: () -> Location
18531 18532 18533 18534 18535 |
# File 'lib/prism/node.rb', line 18531 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
18586 18587 18588 |
# File 'lib/prism/node.rb', line 18586 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
Returns the Location represented by operator_loc.
: () -> Location
18553 18554 18555 18556 18557 |
# File 'lib/prism/node.rb', line 18553 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
18542 18543 18544 |
# File 'lib/prism/node.rb', line 18542 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
18564 18565 18566 |
# File 'lib/prism/node.rb', line 18564 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ :instance_variable_or_write_node
See Node#type.
: () -> :instance_variable_or_write_node
18496 18497 18498 |
# File 'lib/prism/node.rb', line 18496 def type :instance_variable_or_write_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
Returns the value attribute.
: () -> Prism::node
18574 18575 18576 |
# File 'lib/prism/node.rb', line 18574 def value @value end |