Class: SyntaxTree::For
Overview
For represents using a for loop.
for value in list do
end
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
- untyped
-
the object being enumerated in the loop.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#index ⇒ Object
readonly
- MLHS | VarField
-
the variable declaration being used to pull values out of the object being enumerated.
-
#statements ⇒ Object
readonly
- Statements
-
the statements to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(index: nil, collection: nil, statements: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(index:, collection:, statements:, location:) ⇒ For
constructor
A new instance of For.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(index:, collection:, statements:, location:) ⇒ For
5431 5432 5433 5434 5435 5436 5437 |
# File 'lib/syntax_tree/node.rb', line 5431 def initialize(index:, collection:, statements:, location:) @index = index @collection = collection @statements = statements @location = location @comments = [] end |
Instance Attribute Details
#collection ⇒ Object (readonly)
- untyped
-
the object being enumerated in the loop
5423 5424 5425 |
# File 'lib/syntax_tree/node.rb', line 5423 def collection @collection end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5429 5430 5431 |
# File 'lib/syntax_tree/node.rb', line 5429 def comments @comments end |
#index ⇒ Object (readonly)
- MLHS | VarField
-
the variable declaration being used to
pull values out of the object being enumerated
5420 5421 5422 |
# File 'lib/syntax_tree/node.rb', line 5420 def index @index end |
#statements ⇒ Object (readonly)
- Statements
-
the statements to be executed
5426 5427 5428 |
# File 'lib/syntax_tree/node.rb', line 5426 def statements @statements end |
Instance Method Details
#===(other) ⇒ Object
5491 5492 5493 5494 |
# File 'lib/syntax_tree/node.rb', line 5491 def ===(other) other.is_a?(For) && index === other.index && collection === other.collection && statements === other.statements end |
#accept(visitor) ⇒ Object
5439 5440 5441 |
# File 'lib/syntax_tree/node.rb', line 5439 def accept(visitor) visitor.visit_for(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5443 5444 5445 |
# File 'lib/syntax_tree/node.rb', line 5443 def child_nodes [index, collection, statements] end |
#copy(index: nil, collection: nil, statements: nil, location: nil) ⇒ Object
5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 |
# File 'lib/syntax_tree/node.rb', line 5447 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_keys(_keys) ⇒ Object
5462 5463 5464 5465 5466 5467 5468 5469 5470 |
# File 'lib/syntax_tree/node.rb', line 5462 def deconstruct_keys(_keys) { index: index, collection: collection, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 |
# File 'lib/syntax_tree/node.rb', line 5472 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 |