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
Constructor Details
#initialize(index:, collection:, statements:, location:, comments: []) ⇒ For
Returns a new instance of For.
4174 4175 4176 4177 4178 4179 4180 |
# File 'lib/syntax_tree/node.rb', line 4174 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
4166 4167 4168 |
# File 'lib/syntax_tree/node.rb', line 4166 def collection @collection end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4172 4173 4174 |
# File 'lib/syntax_tree/node.rb', line 4172 def comments @comments end |
#index ⇒ Object (readonly)
- MLHS | VarField
-
the variable declaration being used to
pull values out of the object being enumerated
4163 4164 4165 |
# File 'lib/syntax_tree/node.rb', line 4163 def index @index end |
#statements ⇒ Object (readonly)
- Statements
-
the statements to be executed
4169 4170 4171 |
# File 'lib/syntax_tree/node.rb', line 4169 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
4182 4183 4184 |
# File 'lib/syntax_tree/node.rb', line 4182 def accept(visitor) visitor.visit_for(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4186 4187 4188 |
# File 'lib/syntax_tree/node.rb', line 4186 def child_nodes [index, collection, statements] end |
#deconstruct_keys(keys) ⇒ Object
4192 4193 4194 4195 4196 4197 4198 4199 4200 |
# File 'lib/syntax_tree/node.rb', line 4192 def deconstruct_keys(keys) { index: index, collection: collection, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 |
# File 'lib/syntax_tree/node.rb', line 4202 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 |