Class: Prism::ForNode
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
PrismNode
|
|
|
Instance Chain:
self,
PrismNode
|
|
| Inherits: |
PrismNode
|
| Defined in: | lib/prism/node.rb, ext/prism/api_node.c |
Overview
Represents the use of the for keyword.
for i in a end
^^^^^^^^^^^^^^
Class Method Summary
-
.new(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc) ⇒ ForNode
constructor
Initialize a new
ForNodenode. -
.type
Return a symbol representation of this node type.
Instance Attribute Summary
-
#collection
readonly
The collection to iterate over.
-
#index
readonly
The index expression for
forloops. -
#statements
readonly
Represents the body of statements to execute for each iteration of the loop.
Instance Method Summary
-
#===(other)
Implements case-equality for the node.
-
#accept(visitor)
def accept: (Visitor visitor) -> void.
-
#child_nodes
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes
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)
-
#deconstruct
Alias for #child_nodes.
- #deconstruct_keys(keys)
-
#do_keyword
def do_keyword: () -> String?
-
#do_keyword_loc
The location of the
dokeyword, if present. -
#end_keyword
def end_keyword: () -> String.
-
#end_keyword_loc
The location of the
endkeyword. -
#for_keyword
def for_keyword: () -> String.
-
#for_keyword_loc
The location of the
forkeyword. -
#in_keyword
def in_keyword: () -> String.
-
#in_keyword_loc
The location of the
inkeyword. -
#inspect
def inspect -> String.
-
#type
Return a symbol representation of this node type.
Constructor Details
.new(source, node_id, location, flags, index, collection, statements, for_keyword_loc, in_keyword_loc, do_keyword_loc, end_keyword_loc) ⇒ ForNode
Initialize a new ForNode node.
# File 'lib/prism/node.rb', line 6118
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
Class Method Details
.type
Return a symbol representation of this node type. See Node::type.
# File 'lib/prism/node.rb', line 6263
def self.type :for_node end
Instance Attribute Details
#collection (readonly)
The collection to iterate over.
for i in a end
^
# File 'lib/prism/node.rb', line 6178
attr_reader :collection
#index (readonly)
The index expression for for loops.
for i in a end
^
# File 'lib/prism/node.rb', line 6173
attr_reader :index
#statements (readonly)
Represents the body of statements to execute for each iteration of the loop.
for i in a
foo(i)
^^^^^^
end
# File 'lib/prism/node.rb', line 6185
attr_reader :statements
Instance Method Details
#===(other)
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
# File 'lib/prism/node.rb', line 6269
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 'lib/prism/node.rb', line 6133
def accept(visitor) visitor.visit_for_node(self) end
#child_nodes Also known as: #deconstruct
def child_nodes: () -> Array[nil | Node]
# File 'lib/prism/node.rb', line 6138
def child_nodes [index, collection, statements] end
#comment_targets
def comment_targets: () -> Array[Node | Location]
# File 'lib/prism/node.rb', line 6152
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 'lib/prism/node.rb', line 6143
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)
# File 'lib/prism/node.rb', line 6157
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
Alias for #child_nodes.
# File 'lib/prism/node.rb', line 6162
alias deconstruct child_nodes
#deconstruct_keys(keys)
# File 'lib/prism/node.rb', line 6165
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 'lib/prism/node.rb', line 6243
def do_keyword do_keyword_loc&.slice end
#do_keyword_loc
The location of the do keyword, if present.
for i in a do end
^^
#end_keyword
def end_keyword: () -> String
# File 'lib/prism/node.rb', line 6248
def end_keyword end_keyword_loc.slice end
#end_keyword_loc
The location of the end keyword.
for i in a end
^^^
#for_keyword
def for_keyword: () -> String
# File 'lib/prism/node.rb', line 6233
def for_keyword for_keyword_loc.slice end
#for_keyword_loc
The location of the for keyword.
for i in a end
^^^
#in_keyword
def in_keyword: () -> String
# File 'lib/prism/node.rb', line 6238
def in_keyword in_keyword_loc.slice end
#in_keyword_loc
The location of the in keyword.
for i in a end
^^
#inspect
def inspect -> String
# File 'lib/prism/node.rb', line 6253
def inspect InspectVisitor.compose(self) end
#type
Return a symbol representation of this node type. See Node#type.
# File 'lib/prism/node.rb', line 6258
def type :for_node end