class Prism::IndexTargetNode - Documentation for Ruby 4.1
Description: class Prism::IndexTargetNode: Represents assigning to an index.
Keywords: ruby,class,Prism::IndexTargetNode

🔍

No recent searches

# class Prism::IndexTargetNode

Represents assigning to an index.

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

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

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

### Public Class Methods

new (source, node_id, location, flags, receiver, opening_loc, arguments, closing_loc, block)
Source

    # File lib/prism/node.rb, line 16441
    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

Initialize a new `IndexTargetNode` node.

### Public Instance Methods

arguments → ArgumentsNode | nil
Source

    # File lib/prism/node.rb, line 16616
    def arguments
      @arguments
    end

Returns the `arguments` attribute.

block → BlockArgumentNode | nil
Source

    # File lib/prism/node.rb, line 16648
    def block
      @block
    end

Returns the `block` attribute.

receiver → Node
Source

    # File lib/prism/node.rb, line 16584
    def receiver
      @receiver
    end

Returns the `receiver` attribute.

## Flags

### Public Instance Methods

attribute_write? ()
Source

    # File lib/prism/node.rb, line 16566
    def attribute_write?
      flags.anybits?(CallNodeFlags::ATTRIBUTE_WRITE)
    end

a call that is an attribute write, so the value being written should be returned

ignore_visibility? ()
Source

    # File lib/prism/node.rb, line 16574
    def ignore_visibility?
      flags.anybits?(CallNodeFlags::IGNORE_VISIBILITY)
    end

a call that ignores method visibility

variable_call? ()
Source

    # File lib/prism/node.rb, line 16558
    def variable_call?
      flags.anybits?(CallNodeFlags::VARIABLE_CALL)
    end

a call that could have been a local variable

## Locations

### Public Instance Methods

closing_loc → Location
Source

    # File lib/prism/node.rb, line 16627
    def closing_loc
      location = @closing_loc
      return location if location.is_a?(Location)
      @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
    end

Returns the `Location` represented by `closing_loc`.

opening_loc → Location
Source

    # File lib/prism/node.rb, line 16595
    def opening_loc
      location = @opening_loc
      return location if location.is_a?(Location)
      @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
    end

Returns the `Location` represented by `opening_loc`.

## Node Interface

These methods are present on all subclasses of `Node`. Read the node interface docs for more information.

### Public Class Methods

type ()
Source

    # File lib/prism/node.rb, line 16535
    def self.type
      :index_target_node
    end

See `Node.type`.

### Public Instance Methods

accept (visitor)
Source

    # File lib/prism/node.rb, line 16467
    def accept(visitor)
      visitor.visit_index_target_node(self)
    end

See `Node.accept`.

child_nodes ()
Source

    # File lib/prism/node.rb, line 16474
    def child_nodes
      [receiver, arguments, block]
    end

See `Node.child_nodes`.

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 16504
    def comment_targets
      [receiver, opening_loc, *arguments, closing_loc, *block] #: Array[Prism::node | Location]
    end

See `Node.comment_targets`.

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 16493
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      compact << receiver
      if (arguments = self.arguments); compact << arguments; end
      if (block = self.block); compact << block; end
      compact
    end

See `Node.compact_child_nodes`.

copy(**fields) → IndexTargetNode
Source

    # File lib/prism/node.rb, line 16514
    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

Creates a copy of self with the given fields, using self as the template.

deconstruct ()
Alias for: child_nodes
each_child_node () { |receiver| ... }
Source

    # File lib/prism/node.rb, line 16482
    def each_child_node(&blk)
      return to_enum(:each_child_node) unless block_given?

      yield receiver
      if (arguments = self.arguments); yield arguments; end
      if (block = self.block); yield block; end
    end

See `Node.each_child_node`.

type ()
Source

    # File lib/prism/node.rb, line 16528
    def type
      :index_target_node
    end

See `Node#type`.

## Repository

Methods related to `Relocation`.

### Public Instance Methods

save_closing_loc (repository)
Source

    # File lib/prism/node.rb, line 16638
    def save_closing_loc(repository)
      repository.enter(node_id, :closing_loc)
    end

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

save_opening_loc (repository)
Source

    # File lib/prism/node.rb, line 16606
    def save_opening_loc(repository)
      repository.enter(node_id, :opening_loc)
    end

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

## Slicing

### Public Instance Methods

closing → String
Source

    # File lib/prism/node.rb, line 16670
    def closing
      closing_loc.slice
    end

Slice the location of `closing_loc` from the source.

opening → String
Source

    # File lib/prism/node.rb, line 16660
    def opening
      opening_loc.slice
    end

Slice the location of `opening_loc` from the source.