class Prism::ForNode - Documentation for Ruby 4.0
Description: class Prism::ForNode: Represents the use of the `for` keyword.
Keywords: ruby,class,Prism::ForNode

🔍

No recent searches

# class Prism::ForNode

Represents the use of the `for` keyword.

    for i in a end
    ^^^^^^^^^^^^^^

### Attributes

collection [R]

The collection to iterate over.

    for i in a end
             ^

index [R]

The index expression for `for` loops.

    for i in a end
        ^

statements [R]

Represents the body of statements to execute for each iteration of the loop.

    for i in a
      foo(i)
      ^^^^^^
    end

### Public Class Methods

new (source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc)
Source

    # File lib/prism/node.rb, line 7653
    def initialize(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc)
      @source = source
      @node_id = node_id
      @location = location
      @flags = flags
      @index = index
      @collection = collection
      @statements = statements
      @for_keyword_loc = for_keyword_loc
      @in_keyword_loc = in_keyword_loc
      @do_keyword_loc = do_keyword_loc
      @end_keyword_loc = end_keyword_loc
    end

Initialize a new `ForNode` node.

type ()
Source

    # File lib/prism/node.rb, line 7834
    def self.type
      :for_node
    end

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

### Public Instance Methods

=== (other)
Source

    # File lib/prism/node.rb, line 7840
    def ===(other)
      other.is_a?(ForNode) &&
        (index === other.index) &&
        (collection === other.collection) &&
        (statements === other.statements) &&
        (for_keyword_loc.nil? == other.for_keyword_loc.nil?) &&
        (in_keyword_loc.nil? == other.in_keyword_loc.nil?) &&
        (do_keyword_loc.nil? == other.do_keyword_loc.nil?) &&
        (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
    end

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.

accept (visitor)
Source

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

def accept: (`Visitor` visitor) -> void

child_nodes ()
Source

    # File lib/prism/node.rb, line 7673
    def child_nodes
      [index, collection, statements]
    end

def `child_nodes`: () -> Array

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 7696
    def comment_targets
      [index, collection, *statements, for_keyword_loc, in_keyword_loc, *do_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location]
    end

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

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 7687
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      compact << index
      compact << collection
      compact << statements if statements
      compact
    end

def `compact_child_nodes`: () -> Array

copy (node_id: self.node_id, location: self.location, flags: self.flags, index: self.index, collection: self.collection, statements: self.statements, for_keyword_loc: self.for_keyword_loc, in_keyword_loc: self.in_keyword_loc, do_keyword_loc: self.do_keyword_loc, end_keyword_loc: self.end_keyword_loc)
Source

    # File lib/prism/node.rb, line 7701
    def copy(node_id: self.node_id, location: self.location, flags: self.flags, index: self.index, collection: self.collection, statements: self.statements, for_keyword_loc: self.for_keyword_loc, in_keyword_loc: self.in_keyword_loc, do_keyword_loc: self.do_keyword_loc, end_keyword_loc: self.end_keyword_loc)
      ForNode.new(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc)
    end

def copy: (?node_id: `Integer`, ?location: `Location`, ?flags: `Integer`, ?index: `LocalVariableTargetNode` | `InstanceVariableTargetNode` | `ClassVariableTargetNode` | `GlobalVariableTargetNode` | `ConstantTargetNode` | `ConstantPathTargetNode` | `CallTargetNode` | `IndexTargetNode` | `MultiTargetNode` | `BackReferenceReadNode` | `NumberedReferenceReadNode` | `MissingNode`, ?collection: Prism::node, ?statements: `StatementsNode`?, ?for_keyword_loc: `Location`, ?in_keyword_loc: `Location`, ?do_keyword_loc: `Location`?, ?end_keyword_loc: `Location`) -> `ForNode`

deconstruct ()

def deconstruct: () -> Array

Alias for: child_nodes
deconstruct_keys (keys)
Source

    # File lib/prism/node.rb, line 7709
    def deconstruct_keys(keys)
      { node_id: node_id, location: location, index: index, collection: collection, statements: statements, for_keyword_loc: for_keyword_loc, in_keyword_loc: in_keyword_loc, do_keyword_loc: do_keyword_loc, end_keyword_loc: end_keyword_loc }
    end

def `deconstruct_keys`: (Array keys) -> { node_id: `Integer`, location: `Location`, index: `LocalVariableTargetNode` | `InstanceVariableTargetNode` | `ClassVariableTargetNode` | `GlobalVariableTargetNode` | `ConstantTargetNode` | `ConstantPathTargetNode` | `CallTargetNode` | `IndexTargetNode` | `MultiTargetNode` | `BackReferenceReadNode` | `NumberedReferenceReadNode` | `MissingNode`, collection: Prism::node, statements: `StatementsNode`?, `for_keyword_loc`: `Location`, `in_keyword_loc`: `Location`, `do_keyword_loc`: `Location`?, `end_keyword_loc`: `Location` }

do_keyword ()
Source

    # File lib/prism/node.rb, line 7814
    def do_keyword
      do_keyword_loc&.slice
    end

def `do_keyword`: () -> `String`?

do_keyword_loc ()
Source

    # File lib/prism/node.rb, line 7769
    def do_keyword_loc
      location = @do_keyword_loc
      case location
      when nil
        nil
      when Location
        location
      else
        @do_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
      end
    end

The location of the `do` keyword, if present.

    for i in a do end
               ^^

each_child_node () { |index| ... }
Source

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

      yield index
      yield collection
      yield statements if statements
    end

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

end_keyword ()
Source

    # File lib/prism/node.rb, line 7819
    def end_keyword
      end_keyword_loc.slice
    end

def `end_keyword`: () -> `String`

end_keyword_loc ()
Source

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

The location of the `end` keyword.

    for i in a end
               ^^^

for_keyword ()
Source

    # File lib/prism/node.rb, line 7804
    def for_keyword
      for_keyword_loc.slice
    end

def `for_keyword`: () -> `String`

for_keyword_loc ()
Source

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

The location of the `for` keyword.

    for i in a end
    ^^^

in_keyword ()
Source

    # File lib/prism/node.rb, line 7809
    def in_keyword
      in_keyword_loc.slice
    end

def `in_keyword`: () -> `String`

in_keyword_loc ()
Source

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

The location of the `in` keyword.

    for i in a end
          ^^

inspect ()
Source

    # File lib/prism/node.rb, line 7824
    def inspect
      InspectVisitor.compose(self)
    end

def inspect -> `String`

save_do_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 7783
    def save_do_keyword_loc(repository)
      repository.enter(node_id, :do_keyword_loc) unless @do_keyword_loc.nil?
    end

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

save_end_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 7799
    def save_end_keyword_loc(repository)
      repository.enter(node_id, :end_keyword_loc)
    end

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

save_for_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 7745
    def save_for_keyword_loc(repository)
      repository.enter(node_id, :for_keyword_loc)
    end

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

save_in_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 7761
    def save_in_keyword_loc(repository)
      repository.enter(node_id, :in_keyword_loc)
    end

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

type ()
Source

    # File lib/prism/node.rb, line 7829
    def type
      :for_node
    end

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