Class: Prism::ForNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ForNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents the use of the ‘for` keyword.
for i in a end
^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
The collection to iterate over.
-
#index ⇒ Object
readonly
The index expression for ‘for` loops.
-
#statements ⇒ Object
readonly
Represents the body of statements to execute for each iteration of the loop.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
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) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?index: Prism::node, ?collection: Prism::node, ?statements: StatementsNode?, ?for_keyword_loc: Location, ?in_keyword_loc: Location, ?do_keyword_loc: Location?, ?end_keyword_loc: Location) -> ForNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, index: Prism::node, collection: Prism::node, statements: StatementsNode?, for_keyword_loc: Location, in_keyword_loc: Location, do_keyword_loc: Location?, end_keyword_loc: Location }.
-
#do_keyword ⇒ Object
def do_keyword: () -> String?.
-
#do_keyword_loc ⇒ Object
The location of the ‘do` keyword, if present.
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#end_keyword_loc ⇒ Object
The location of the ‘end` keyword.
-
#for_keyword ⇒ Object
def for_keyword: () -> String.
-
#for_keyword_loc ⇒ Object
The location of the ‘for` keyword.
-
#in_keyword ⇒ Object
def in_keyword: () -> String.
-
#in_keyword_loc ⇒ Object
The location of the ‘in` keyword.
-
#initialize(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 ForNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(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.
6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 |
# File 'lib/prism/node.rb', line 6238 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 |
Instance Attribute Details
#collection ⇒ Object (readonly)
The collection to iterate over.
for i in a end
^
6299 6300 6301 |
# File 'lib/prism/node.rb', line 6299 def collection @collection end |
#index ⇒ Object (readonly)
The index expression for ‘for` loops.
for i in a end
^
6293 6294 6295 |
# File 'lib/prism/node.rb', line 6293 def index @index end |
#statements ⇒ Object (readonly)
Represents the body of statements to execute for each iteration of the loop.
for i in a
foo(i)
^^^^^^
end
6307 6308 6309 |
# File 'lib/prism/node.rb', line 6307 def statements @statements end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
6386 6387 6388 |
# File 'lib/prism/node.rb', line 6386 def self.type :for_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 |
# File 'lib/prism/node.rb', line 6392 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) ⇒ Object
def accept: (Visitor visitor) -> void
6253 6254 6255 |
# File 'lib/prism/node.rb', line 6253 def accept(visitor) visitor.visit_for_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
6258 6259 6260 |
# File 'lib/prism/node.rb', line 6258 def child_nodes [index, collection, statements] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
6272 6273 6274 |
# File 'lib/prism/node.rb', line 6272 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 ⇒ Object
def compact_child_nodes: () -> Array
6263 6264 6265 6266 6267 6268 6269 |
# File 'lib/prism/node.rb', line 6263 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) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?index: Prism::node, ?collection: Prism::node, ?statements: StatementsNode?, ?for_keyword_loc: Location, ?in_keyword_loc: Location, ?do_keyword_loc: Location?, ?end_keyword_loc: Location) -> ForNode
6277 6278 6279 |
# File 'lib/prism/node.rb', line 6277 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_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, index: Prism::node, collection: Prism::node, statements: StatementsNode?, for_keyword_loc: Location, in_keyword_loc: Location, do_keyword_loc: Location?, end_keyword_loc: Location }
6285 6286 6287 |
# File 'lib/prism/node.rb', line 6285 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 ⇒ Object
def do_keyword: () -> String?
6366 6367 6368 |
# File 'lib/prism/node.rb', line 6366 def do_keyword do_keyword_loc&.slice end |
#do_keyword_loc ⇒ Object
The location of the ‘do` keyword, if present.
for i in a do end
^^
6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 |
# File 'lib/prism/node.rb', line 6333 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 ⇒ Object
def end_keyword: () -> String
6371 6372 6373 |
# File 'lib/prism/node.rb', line 6371 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
The location of the ‘end` keyword.
for i in a end
^^^
6349 6350 6351 6352 6353 |
# File 'lib/prism/node.rb', line 6349 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 ⇒ Object
def for_keyword: () -> String
6356 6357 6358 |
# File 'lib/prism/node.rb', line 6356 def for_keyword for_keyword_loc.slice end |
#for_keyword_loc ⇒ Object
The location of the ‘for` keyword.
for i in a end
^^^
6313 6314 6315 6316 6317 |
# File 'lib/prism/node.rb', line 6313 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 ⇒ Object
def in_keyword: () -> String
6361 6362 6363 |
# File 'lib/prism/node.rb', line 6361 def in_keyword in_keyword_loc.slice end |
#in_keyword_loc ⇒ Object
The location of the ‘in` keyword.
for i in a end
^^
6323 6324 6325 6326 6327 |
# File 'lib/prism/node.rb', line 6323 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 ⇒ Object
def inspect -> String
6376 6377 6378 |
# File 'lib/prism/node.rb', line 6376 def inspect InspectVisitor.compose(self) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
6381 6382 6383 |
# File 'lib/prism/node.rb', line 6381 def type :for_node end |