Class: Prism::IndexOrWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::IndexOrWriteNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents the use of the ‘||=` operator on a call to [].
foo.[baz] ||= value
^^^^^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
attr_reader arguments: ArgumentsNode?.
-
#block ⇒ Object
readonly
attr_reader block: BlockArgumentNode?.
-
#receiver ⇒ Object
readonly
attr_reader receiver: Prism::node?.
-
#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.
-
#attribute_write? ⇒ Boolean
def attribute_write?: () -> bool.
-
#call_operator ⇒ Object
def call_operator: () -> String?.
-
#call_operator_loc ⇒ Object
attr_reader call_operator_loc: Location?.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#closing ⇒ Object
def closing: () -> String.
-
#closing_loc ⇒ Object
attr_reader closing_loc: Location.
-
#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, receiver: self.receiver, call_operator_loc: self.call_operator_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block, operator_loc: self.operator_loc, value: self.value) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?opening_loc: Location, ?arguments: ArgumentsNode?, ?closing_loc: Location, ?block: BlockArgumentNode?, ?operator_loc: Location, ?value: Prism::node) -> IndexOrWriteNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, opening_loc: Location, arguments: ArgumentsNode?, closing_loc: Location, block: BlockArgumentNode?, operator_loc: Location, value: Prism::node }.
-
#each_child_node {|receiver| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#ignore_visibility? ⇒ Boolean
def ignore_visibility?: () -> bool.
-
#initialize(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator_loc, value) ⇒ IndexOrWriteNode
constructor
Initialize a new IndexOrWriteNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#opening ⇒ Object
def opening: () -> String.
-
#opening_loc ⇒ Object
attr_reader opening_loc: Location.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location.
-
#safe_navigation? ⇒ Boolean
def safe_navigation?: () -> bool.
-
#save_call_operator_loc(repository) ⇒ Object
Save the call_operator_loc location using the given saved source so that it can be retrieved later.
-
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Object
Save the opening_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.
-
#variable_call? ⇒ Boolean
def variable_call?: () -> bool.
Constructor Details
#initialize(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator_loc, value) ⇒ IndexOrWriteNode
Initialize a new IndexOrWriteNode node.
10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 |
# File 'lib/prism/node.rb', line 10113 def initialize(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator_loc, value) @source = source @node_id = node_id @location = location @flags = flags @receiver = receiver @call_operator_loc = call_operator_loc @opening_loc = opening_loc @arguments = arguments @closing_loc = closing_loc @block = block @operator_loc = operator_loc @value = value end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
attr_reader arguments: ArgumentsNode?
10232 10233 10234 |
# File 'lib/prism/node.rb', line 10232 def arguments @arguments end |
#block ⇒ Object (readonly)
attr_reader block: BlockArgumentNode?
10248 10249 10250 |
# File 'lib/prism/node.rb', line 10248 def block @block end |
#receiver ⇒ Object (readonly)
attr_reader receiver: Prism::node?
10197 10198 10199 |
# File 'lib/prism/node.rb', line 10197 def receiver @receiver end |
#value ⇒ Object (readonly)
attr_reader value: Prism::node
10264 10265 10266 |
# File 'lib/prism/node.rb', line 10264 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
10297 10298 10299 |
# File 'lib/prism/node.rb', line 10297 def self.type :index_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.
10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 |
# File 'lib/prism/node.rb', line 10303 def ===(other) other.is_a?(IndexOrWriteNode) && (flags === other.flags) && (receiver === other.receiver) && (call_operator_loc.nil? == other.call_operator_loc.nil?) && (opening_loc.nil? == other.opening_loc.nil?) && (arguments === other.arguments) && (closing_loc.nil? == other.closing_loc.nil?) && (block === other.block) && (operator_loc.nil? == other.operator_loc.nil?) && (value === other.value) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
10129 10130 10131 |
# File 'lib/prism/node.rb', line 10129 def accept(visitor) visitor.visit_index_or_write_node(self) end |
#attribute_write? ⇒ Boolean
def attribute_write?: () -> bool
10187 10188 10189 |
# File 'lib/prism/node.rb', line 10187 def attribute_write? flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE) end |
#call_operator ⇒ Object
def call_operator: () -> String?
10267 10268 10269 |
# File 'lib/prism/node.rb', line 10267 def call_operator call_operator_loc&.slice end |
#call_operator_loc ⇒ Object
attr_reader call_operator_loc: Location?
10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 |
# File 'lib/prism/node.rb', line 10200 def call_operator_loc location = @call_operator_loc case location when nil nil when Location location else @call_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
10134 10135 10136 |
# File 'lib/prism/node.rb', line 10134 def child_nodes [receiver, arguments, block, value] end |
#closing ⇒ Object
def closing: () -> String
10277 10278 10279 |
# File 'lib/prism/node.rb', line 10277 def closing closing_loc.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location
10235 10236 10237 10238 10239 |
# File 'lib/prism/node.rb', line 10235 def closing_loc location = @closing_loc return location if location.is_a?(Location) @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
10159 10160 10161 |
# File 'lib/prism/node.rb', line 10159 def comment_targets [*receiver, *call_operator_loc, opening_loc, *arguments, closing_loc, *block, operator_loc, value] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
10149 10150 10151 10152 10153 10154 10155 10156 |
# File 'lib/prism/node.rb', line 10149 def compact_child_nodes compact = [] #: Array[Prism::node] compact << receiver if receiver compact << arguments if arguments compact << block if block compact << value compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block, operator_loc: self.operator_loc, value: self.value) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node?, ?call_operator_loc: Location?, ?opening_loc: Location, ?arguments: ArgumentsNode?, ?closing_loc: Location, ?block: BlockArgumentNode?, ?operator_loc: Location, ?value: Prism::node) -> IndexOrWriteNode
10164 10165 10166 |
# File 'lib/prism/node.rb', line 10164 def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, call_operator_loc: self.call_operator_loc, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block, operator_loc: self.operator_loc, value: self.value) IndexOrWriteNode.new(source, node_id, location, flags, receiver, call_operator_loc, opening_loc, arguments, closing_loc, block, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, receiver: Prism::node?, call_operator_loc: Location?, opening_loc: Location, arguments: ArgumentsNode?, closing_loc: Location, block: BlockArgumentNode?, operator_loc: Location, value: Prism::node }
10172 10173 10174 |
# File 'lib/prism/node.rb', line 10172 def deconstruct_keys(keys) { node_id: node_id, location: location, receiver: receiver, call_operator_loc: call_operator_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block, operator_loc: operator_loc, value: value } end |
#each_child_node {|receiver| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator
10139 10140 10141 10142 10143 10144 10145 10146 |
# File 'lib/prism/node.rb', line 10139 def each_child_node return to_enum(:each_child_node) unless block_given? yield receiver if receiver yield arguments if arguments yield block if block yield value end |
#ignore_visibility? ⇒ Boolean
def ignore_visibility?: () -> bool
10192 10193 10194 |
# File 'lib/prism/node.rb', line 10192 def ignore_visibility? flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY) end |
#inspect ⇒ Object
def inspect -> String
10287 10288 10289 |
# File 'lib/prism/node.rb', line 10287 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String
10272 10273 10274 |
# File 'lib/prism/node.rb', line 10272 def opening opening_loc.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location
10219 10220 10221 10222 10223 |
# File 'lib/prism/node.rb', line 10219 def opening_loc location = @opening_loc return location if location.is_a?(Location) @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ Object
def operator: () -> String
10282 10283 10284 |
# File 'lib/prism/node.rb', line 10282 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
10251 10252 10253 10254 10255 |
# File 'lib/prism/node.rb', line 10251 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#safe_navigation? ⇒ Boolean
def safe_navigation?: () -> bool
10177 10178 10179 |
# File 'lib/prism/node.rb', line 10177 def flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) end |
#save_call_operator_loc(repository) ⇒ Object
Save the call_operator_loc location using the given saved source so that it can be retrieved later.
10214 10215 10216 |
# File 'lib/prism/node.rb', line 10214 def save_call_operator_loc(repository) repository.enter(node_id, :call_operator_loc) unless @call_operator_loc.nil? end |
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
10243 10244 10245 |
# File 'lib/prism/node.rb', line 10243 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) end |
#save_opening_loc(repository) ⇒ Object
Save the opening_loc location using the given saved source so that it can be retrieved later.
10227 10228 10229 |
# File 'lib/prism/node.rb', line 10227 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) end |
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
10259 10260 10261 |
# File 'lib/prism/node.rb', line 10259 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`.
10292 10293 10294 |
# File 'lib/prism/node.rb', line 10292 def type :index_or_write_node end |
#variable_call? ⇒ Boolean
def variable_call?: () -> bool
10182 10183 10184 |
# File 'lib/prism/node.rb', line 10182 def variable_call? flags.anybits?(CallNodeFlags::VARIABLE_CALL) end |