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.bar[baz] ||= value
^^^^^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
attr_reader arguments: ArgumentsNode?.
-
#block ⇒ Object
readonly
attr_reader block: Prism::node?.
-
#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[nil | Node].
-
#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: Prism::node?, ?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: Prism::node?, operator_loc: Location, value: Prism::node }.
-
#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.
-
#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.
8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 |
# File 'lib/prism/node.rb', line 8334 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?
8431 8432 8433 |
# File 'lib/prism/node.rb', line 8431 def arguments @arguments end |
#block ⇒ Object (readonly)
attr_reader block: Prism::node?
8441 8442 8443 |
# File 'lib/prism/node.rb', line 8441 def block @block end |
#receiver ⇒ Object (readonly)
attr_reader receiver: Prism::node?
8408 8409 8410 |
# File 'lib/prism/node.rb', line 8408 def receiver @receiver end |
#value ⇒ Object (readonly)
attr_reader value: Prism::node
8451 8452 8453 |
# File 'lib/prism/node.rb', line 8451 def value @value end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
8484 8485 8486 |
# File 'lib/prism/node.rb', line 8484 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.
8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 |
# File 'lib/prism/node.rb', line 8490 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
8350 8351 8352 |
# File 'lib/prism/node.rb', line 8350 def accept(visitor) visitor.visit_index_or_write_node(self) end |
#attribute_write? ⇒ Boolean
def attribute_write?: () -> bool
8398 8399 8400 |
# File 'lib/prism/node.rb', line 8398 def attribute_write? flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE) end |
#call_operator ⇒ Object
def call_operator: () -> String?
8454 8455 8456 |
# File 'lib/prism/node.rb', line 8454 def call_operator call_operator_loc&.slice end |
#call_operator_loc ⇒ Object
attr_reader call_operator_loc: Location?
8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 |
# File 'lib/prism/node.rb', line 8411 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[nil | Node]
8355 8356 8357 |
# File 'lib/prism/node.rb', line 8355 def child_nodes [receiver, arguments, block, value] end |
#closing ⇒ Object
def closing: () -> String
8464 8465 8466 |
# File 'lib/prism/node.rb', line 8464 def closing closing_loc.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location
8434 8435 8436 8437 8438 |
# File 'lib/prism/node.rb', line 8434 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]
8370 8371 8372 |
# File 'lib/prism/node.rb', line 8370 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
8360 8361 8362 8363 8364 8365 8366 8367 |
# File 'lib/prism/node.rb', line 8360 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: Prism::node?, ?operator_loc: Location, ?value: Prism::node) -> IndexOrWriteNode
8375 8376 8377 |
# File 'lib/prism/node.rb', line 8375 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: Prism::node?, operator_loc: Location, value: Prism::node }
8383 8384 8385 |
# File 'lib/prism/node.rb', line 8383 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 |
#ignore_visibility? ⇒ Boolean
def ignore_visibility?: () -> bool
8403 8404 8405 |
# File 'lib/prism/node.rb', line 8403 def ignore_visibility? flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY) end |
#inspect ⇒ Object
def inspect -> String
8474 8475 8476 |
# File 'lib/prism/node.rb', line 8474 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String
8459 8460 8461 |
# File 'lib/prism/node.rb', line 8459 def opening opening_loc.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location
8424 8425 8426 8427 8428 |
# File 'lib/prism/node.rb', line 8424 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
8469 8470 8471 |
# File 'lib/prism/node.rb', line 8469 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
8444 8445 8446 8447 8448 |
# File 'lib/prism/node.rb', line 8444 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
8388 8389 8390 |
# File 'lib/prism/node.rb', line 8388 def flags.anybits?(CallNodeFlags::SAFE_NAVIGATION) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
8479 8480 8481 |
# File 'lib/prism/node.rb', line 8479 def type :index_or_write_node end |
#variable_call? ⇒ Boolean
def variable_call?: () -> bool
8393 8394 8395 |
# File 'lib/prism/node.rb', line 8393 def variable_call? flags.anybits?(CallNodeFlags::VARIABLE_CALL) end |