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
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(index:, collection:, statements:, location:, comments: []) ⇒ For
constructor
A new instance of For.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(index:, collection:, statements:, location:, comments: []) ⇒ For
Returns a new instance of For.
4618 4619 4620 4621 4622 4623 4624 |
# File 'lib/syntax_tree/node.rb', line 4618 def initialize(index:, collection:, statements:, location:, comments: []) @index = index @collection = collection @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#collection ⇒ Object (readonly)
- untyped
-
the object being enumerated in the loop
4610 4611 4612 |
# File 'lib/syntax_tree/node.rb', line 4610 def collection @collection end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4616 4617 4618 |
# File 'lib/syntax_tree/node.rb', line 4616 def comments @comments end |
#index ⇒ Object (readonly)
- MLHS | VarField
-
the variable declaration being used to
pull values out of the object being enumerated
4607 4608 4609 |
# File 'lib/syntax_tree/node.rb', line 4607 def index @index end |
#statements ⇒ Object (readonly)
- Statements
-
the statements to be executed
4613 4614 4615 |
# File 'lib/syntax_tree/node.rb', line 4613 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
4626 4627 4628 |
# File 'lib/syntax_tree/node.rb', line 4626 def accept(visitor) visitor.visit_for(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4630 4631 4632 |
# File 'lib/syntax_tree/node.rb', line 4630 def child_nodes [index, collection, statements] end |
#deconstruct_keys(_keys) ⇒ Object
4636 4637 4638 4639 4640 4641 4642 4643 4644 |
# File 'lib/syntax_tree/node.rb', line 4636 def deconstruct_keys(_keys) { index: index, collection: collection, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 |
# File 'lib/syntax_tree/node.rb', line 4646 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: true) q.format(statements) end end q.breakable(force: true) q.text("end") end end |