class SyntaxTree::For

For represents using a for loop.

for value in list do
end

Attributes

collection[R]
Node

the object being enumerated in the loop

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

index[R]
MLHS | VarField

the variable declaration being used to

pull values out of the object being enumerated

statements[R]
Statements

the statements to be executed

Public Class Methods

new(index:, collection:, statements:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 5530
def initialize(index:, collection:, statements:, location:)
  @index = index
  @collection = collection
  @statements = statements
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 5590
def ===(other)
  other.is_a?(For) && index === other.index &&
    collection === other.collection && statements === other.statements
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 5538
def accept(visitor)
  visitor.visit_for(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 5542
def child_nodes
  [index, collection, statements]
end
Also aliased as: deconstruct
copy(index: nil, collection: nil, statements: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 5546
def copy(index: nil, collection: nil, statements: nil, location: nil)
  node =
    For.new(
      index: index || self.index,
      collection: collection || self.collection,
      statements: statements || self.statements,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 5561
def deconstruct_keys(_keys)
  {
    index: index,
    collection: collection,
    statements: statements,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 5571
def format(q)
  q.group do
    q.text("for ")
    q.group { q.format(index) }
    q.text(" in ")
    q.format(collection)

    unless statements.empty?
      q.indent do
        q.breakable_force
        q.format(statements)
      end
    end

    q.breakable_force
    q.text("end")
  end
end