Class: Prism::InstanceVariableOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::InstanceVariableOrWriteNode
- 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 an instance variable.
@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.
-
#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) -> InstanceVariableOrWriteNode.
-
#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) ⇒ InstanceVariableOrWriteNode
constructor
Initialize a new InstanceVariableOrWriteNode 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.
-
#save_name_loc(repository) ⇒ Object
Save the name_loc location using the given saved source so that it can be retrieved later.
-
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, name, name_loc, operator_loc, value) ⇒ InstanceVariableOrWriteNode
Initialize a new InstanceVariableOrWriteNode node.
10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 |
# File 'lib/prism/node.rb', line 10135 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
10180 10181 10182 |
# File 'lib/prism/node.rb', line 10180 def name @name end |
#value ⇒ Object (readonly)
attr_reader value: Prism::node
10209 10210 10211 |
# File 'lib/prism/node.rb', line 10209 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
10227 10228 10229 |
# File 'lib/prism/node.rb', line 10227 def self.type :instance_variable_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.
10233 10234 10235 10236 10237 10238 10239 |
# File 'lib/prism/node.rb', line 10233 def ===(other) 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
def accept: (Visitor visitor) -> void
10147 10148 10149 |
# File 'lib/prism/node.rb', line 10147 def accept(visitor) visitor.visit_instance_variable_or_write_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
10152 10153 10154 |
# File 'lib/prism/node.rb', line 10152 def child_nodes [value] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
10162 10163 10164 |
# File 'lib/prism/node.rb', line 10162 def comment_targets [name_loc, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
10157 10158 10159 |
# File 'lib/prism/node.rb', line 10157 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) -> InstanceVariableOrWriteNode
10167 10168 10169 |
# File 'lib/prism/node.rb', line 10167 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) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, operator_loc: Location, value: Prism::node }
10175 10176 10177 |
# File 'lib/prism/node.rb', line 10175 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:
225 226 227 |
# File 'lib/prism/desugar_compiler.rb', line 225 def desugar # :nodoc: DesugarOrWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile end |
#inspect ⇒ Object
def inspect -> String
10217 10218 10219 |
# File 'lib/prism/node.rb', line 10217 def inspect InspectVisitor.compose(self) end |
#name_loc ⇒ Object
attr_reader name_loc: Location
10183 10184 10185 10186 10187 |
# File 'lib/prism/node.rb', line 10183 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
10212 10213 10214 |
# File 'lib/prism/node.rb', line 10212 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
10196 10197 10198 10199 10200 |
# File 'lib/prism/node.rb', line 10196 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) ⇒ Object
Save the name_loc location using the given saved source so that it can be retrieved later.
10191 10192 10193 |
# File 'lib/prism/node.rb', line 10191 def save_name_loc(repository) repository.enter(node_id, :name_loc) end |
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
10204 10205 10206 |
# File 'lib/prism/node.rb', line 10204 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
10222 10223 10224 |
# File 'lib/prism/node.rb', line 10222 def type :instance_variable_or_write_node end |