Class: Prism::IndexOrWriteNode

Inherits:
PrismNode
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.



8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
# File 'lib/prism/node.rb', line 8371

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

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



8468
8469
8470
# File 'lib/prism/node.rb', line 8468

def arguments
  @arguments
end

#blockObject (readonly)

attr_reader block: BlockArgumentNode?



8478
8479
8480
# File 'lib/prism/node.rb', line 8478

def block
  @block
end

#receiverObject (readonly)

attr_reader receiver: Prism::node?



8445
8446
8447
# File 'lib/prism/node.rb', line 8445

def receiver
  @receiver
end

#valueObject (readonly)

attr_reader value: Prism::node



8488
8489
8490
# File 'lib/prism/node.rb', line 8488

def value
  @value
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



8521
8522
8523
# File 'lib/prism/node.rb', line 8521

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.



8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
# File 'lib/prism/node.rb', line 8527

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



8387
8388
8389
# File 'lib/prism/node.rb', line 8387

def accept(visitor)
  visitor.visit_index_or_write_node(self)
end

#attribute_write?Boolean

def attribute_write?: () -> bool

Returns:

  • (Boolean)


8435
8436
8437
# File 'lib/prism/node.rb', line 8435

def attribute_write?
  flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
end

#call_operatorObject

def call_operator: () -> String?



8491
8492
8493
# File 'lib/prism/node.rb', line 8491

def call_operator
  call_operator_loc&.slice
end

#call_operator_locObject

attr_reader call_operator_loc: Location?



8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
# File 'lib/prism/node.rb', line 8448

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_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



8392
8393
8394
# File 'lib/prism/node.rb', line 8392

def child_nodes
  [receiver, arguments, block, value]
end

#closingObject

def closing: () -> String



8501
8502
8503
# File 'lib/prism/node.rb', line 8501

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



8471
8472
8473
8474
8475
# File 'lib/prism/node.rb', line 8471

def closing_loc
  location = @closing_loc
  return location if location.is_a?(Location)
  @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



8407
8408
8409
# File 'lib/prism/node.rb', line 8407

def comment_targets
  [*receiver, *call_operator_loc, opening_loc, *arguments, closing_loc, *block, operator_loc, value] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



8397
8398
8399
8400
8401
8402
8403
8404
# File 'lib/prism/node.rb', line 8397

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



8412
8413
8414
# File 'lib/prism/node.rb', line 8412

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 }



8420
8421
8422
# File 'lib/prism/node.rb', line 8420

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

Returns:

  • (Boolean)


8440
8441
8442
# File 'lib/prism/node.rb', line 8440

def ignore_visibility?
  flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
end

#inspectObject

def inspect -> String



8511
8512
8513
# File 'lib/prism/node.rb', line 8511

def inspect
  InspectVisitor.compose(self)
end

#openingObject

def opening: () -> String



8496
8497
8498
# File 'lib/prism/node.rb', line 8496

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



8461
8462
8463
8464
8465
# File 'lib/prism/node.rb', line 8461

def opening_loc
  location = @opening_loc
  return location if location.is_a?(Location)
  @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#operatorObject

def operator: () -> String



8506
8507
8508
# File 'lib/prism/node.rb', line 8506

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



8481
8482
8483
8484
8485
# File 'lib/prism/node.rb', line 8481

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

Returns:

  • (Boolean)


8425
8426
8427
# File 'lib/prism/node.rb', line 8425

def safe_navigation?
  flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



8516
8517
8518
# File 'lib/prism/node.rb', line 8516

def type
  :index_or_write_node
end

#variable_call?Boolean

def variable_call?: () -> bool

Returns:

  • (Boolean)


8430
8431
8432
# File 'lib/prism/node.rb', line 8430

def variable_call?
  flags.anybits?(CallNodeFlags::VARIABLE_CALL)
end