Class: Prism::IndexTargetNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents assigning to an index.

foo[bar], = 1
^^^^^^^^

begin
rescue => foo[bar]
          ^^^^^^^^
end

for foo[bar] in baz do end
    ^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block) ⇒ IndexTargetNode

Initialize a new IndexTargetNode node.



10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
# File 'lib/prism/node.rb', line 10331

def initialize(source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @receiver = receiver
  @opening_loc = opening_loc
  @arguments = arguments
  @closing_loc = closing_loc
  @block = block
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



10426
10427
10428
# File 'lib/prism/node.rb', line 10426

def arguments
  @arguments
end

#blockObject (readonly)

attr_reader block: BlockArgumentNode?



10442
10443
10444
# File 'lib/prism/node.rb', line 10442

def block
  @block
end

#receiverObject (readonly)

attr_reader receiver: Prism::node



10410
10411
10412
# File 'lib/prism/node.rb', line 10410

def receiver
  @receiver
end

Class Method Details

.typeObject

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



10465
10466
10467
# File 'lib/prism/node.rb', line 10465

def self.type
  :index_target_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.



10471
10472
10473
10474
10475
10476
10477
10478
10479
# File 'lib/prism/node.rb', line 10471

def ===(other)
  other.is_a?(IndexTargetNode) &&
    (flags === other.flags) &&
    (receiver === other.receiver) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (arguments === other.arguments) &&
    (closing_loc.nil? == other.closing_loc.nil?) &&
    (block === other.block)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



10344
10345
10346
# File 'lib/prism/node.rb', line 10344

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

#attribute_write?Boolean

def attribute_write?: () -> bool

Returns:

  • (Boolean)


10400
10401
10402
# File 'lib/prism/node.rb', line 10400

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



10349
10350
10351
# File 'lib/prism/node.rb', line 10349

def child_nodes
  [receiver, arguments, block]
end

#closingObject

def closing: () -> String



10450
10451
10452
# File 'lib/prism/node.rb', line 10450

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



10429
10430
10431
10432
10433
# File 'lib/prism/node.rb', line 10429

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]



10372
10373
10374
# File 'lib/prism/node.rb', line 10372

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



10363
10364
10365
10366
10367
10368
10369
# File 'lib/prism/node.rb', line 10363

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << receiver
  compact << arguments if arguments
  compact << block if block
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?receiver: Prism::node, ?opening_loc: Location, ?arguments: ArgumentsNode?, ?closing_loc: Location, ?block: BlockArgumentNode?) -> IndexTargetNode



10377
10378
10379
# File 'lib/prism/node.rb', line 10377

def copy(node_id: self.node_id, location: self.location, flags: self.flags, receiver: self.receiver, opening_loc: self.opening_loc, arguments: self.arguments, closing_loc: self.closing_loc, block: self.block)
  IndexTargetNode.new(source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, receiver: Prism::node, opening_loc: Location, arguments: ArgumentsNode?, closing_loc: Location, block: BlockArgumentNode? }



10385
10386
10387
# File 'lib/prism/node.rb', line 10385

def deconstruct_keys(keys)
  { node_id: node_id, location: location, receiver: receiver, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, block: block }
end

#each_child_node {|receiver| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



10354
10355
10356
10357
10358
10359
10360
# File 'lib/prism/node.rb', line 10354

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield receiver
  yield arguments if arguments
  yield block if block
end

#ignore_visibility?Boolean

def ignore_visibility?: () -> bool

Returns:

  • (Boolean)


10405
10406
10407
# File 'lib/prism/node.rb', line 10405

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

#inspectObject

def inspect -> String



10455
10456
10457
# File 'lib/prism/node.rb', line 10455

def inspect
  InspectVisitor.compose(self)
end

#openingObject

def opening: () -> String



10445
10446
10447
# File 'lib/prism/node.rb', line 10445

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



10413
10414
10415
10416
10417
# File 'lib/prism/node.rb', line 10413

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

#safe_navigation?Boolean

def safe_navigation?: () -> bool

Returns:

  • (Boolean)


10390
10391
10392
# File 'lib/prism/node.rb', line 10390

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

#save_closing_loc(repository) ⇒ Object

Save the closing_loc location using the given saved source so that it can be retrieved later.



10437
10438
10439
# File 'lib/prism/node.rb', line 10437

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.



10421
10422
10423
# File 'lib/prism/node.rb', line 10421

def save_opening_loc(repository)
  repository.enter(node_id, :opening_loc)
end

#typeObject

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



10460
10461
10462
# File 'lib/prism/node.rb', line 10460

def type
  :index_target_node
end

#variable_call?Boolean

def variable_call?: () -> bool

Returns:

  • (Boolean)


10395
10396
10397
# File 'lib/prism/node.rb', line 10395

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