class Prism::ForNode

表示使用了 ‘for’ 关键字。

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

属性

collection[R]

要迭代的集合。

for i in a end
         ^
index[R]

‘for’ 循环的索引表达式。

for i in a end
    ^
statements[R]

表示每次循环迭代要执行的语句体。

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

公共类方法

new(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc) 点击以切换源代码

初始化一个新的 ForNode 节点。

# File prism/node.rb, line 7144
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
type() 点击以切换源代码

返回此节点类型的符号表示。参见 ‘Node::type’。

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

公共实例方法

===(other) 点击以切换源代码

为节点实现 case-equality。这实际上是 ==,但不比较位置的值。位置仅检查是否存在。

# File prism/node.rb, line 7322
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
accept(visitor) 点击以切换源代码

def accept: (Visitor visitor) -> void

# File prism/node.rb, line 7159
def accept(visitor)
  visitor.visit_for_node(self)
end
child_nodes() 点击以切换源代码

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

# File prism/node.rb, line 7164
def child_nodes
  [index, collection, statements]
end
别名为:deconstruct
comment_targets() 点击以切换源代码

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

# File prism/node.rb, line 7178
def comment_targets
  [index, collection, *statements, for_keyword_loc, in_keyword_loc, *do_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location]
end
compact_child_nodes() 点击以切换源代码

def compact_child_nodes: () -> Array

# File prism/node.rb, line 7169
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << index
  compact << collection
  compact << statements if statements
  compact
end
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) 点击以切换源代码

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

# File prism/node.rb, line 7183
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
deconstruct()

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

别名为:child_nodes
deconstruct_keys(keys) 点击以切换源代码

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 }

# File prism/node.rb, line 7191
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
do_keyword() 点击以切换源代码

def do_keyword: () -> String?

# File prism/node.rb, line 7296
def do_keyword
  do_keyword_loc&.slice
end
do_keyword_loc() 点击以切换源代码

如果存在,则为 ‘do’ 关键字的位置。

for i in a do end
           ^^
# File prism/node.rb, line 7251
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
end_keyword() 点击以切换源代码

def end_keyword: () -> String

# File prism/node.rb, line 7301
def end_keyword
  end_keyword_loc.slice
end
end_keyword_loc() 点击以切换源代码

‘end’ 关键字的位置。

for i in a end
           ^^^
# File prism/node.rb, line 7273
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
for_keyword() 点击以切换源代码

def for_keyword: () -> String

# File prism/node.rb, line 7286
def for_keyword
  for_keyword_loc.slice
end
for_keyword_loc() 点击以切换源代码

‘for’ 关键字的位置。

for i in a end
^^^
# File prism/node.rb, line 7219
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
in_keyword() 点击以切换源代码

def in_keyword: () -> String

# File prism/node.rb, line 7291
def in_keyword
  in_keyword_loc.slice
end
in_keyword_loc() 点击以切换源代码

‘in’ 关键字的位置。

for i in a end
      ^^
# File prism/node.rb, line 7235
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
inspect() 点击以切换源代码

def inspect -> String

# File prism/node.rb, line 7306
def inspect
  InspectVisitor.compose(self)
end
save_do_keyword_loc(repository) 点击以切换源代码

使用给定的已保存的源保存 do_keyword_loc 位置,以便稍后可以检索。

# File prism/node.rb, line 7265
def save_do_keyword_loc(repository)
  repository.enter(node_id, :do_keyword_loc) unless @do_keyword_loc.nil?
end
save_end_keyword_loc(repository) 点击以切换源代码

使用给定的已保存的源保存 end_keyword_loc 位置,以便稍后可以检索。

# File prism/node.rb, line 7281
def save_end_keyword_loc(repository)
  repository.enter(node_id, :end_keyword_loc)
end
save_for_keyword_loc(repository) 点击以切换源代码

使用给定的已保存的源保存 for_keyword_loc 位置,以便稍后可以检索。

# File prism/node.rb, line 7227
def save_for_keyword_loc(repository)
  repository.enter(node_id, :for_keyword_loc)
end
save_in_keyword_loc(repository) 点击以切换源代码

使用给定的已保存的源保存 in_keyword_loc 位置,以便稍后可以检索。

# File prism/node.rb, line 7243
def save_in_keyword_loc(repository)
  repository.enter(node_id, :in_keyword_loc)
end
type() 点击以切换源代码

返回此节点类型的符号表示。参见 ‘Node#type’。

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