Class: SyntaxTree::ENDBlock
Overview
ENDBlock represents the use of the END keyword, which hooks into the lifecycle of the interpreter. Whatever is inside the block will get executed when the program ends.
END {
}
Interestingly, the END keyword doesn’t allow the do and end keywords for the block. Only braces are permitted.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#lbrace ⇒ Object
readonly
- LBrace
-
the left brace that is seen after the keyword.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions 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(lbrace:, statements:, location:, comments: []) ⇒ ENDBlock
constructor
A new instance of ENDBlock.
Methods inherited from Node
Constructor Details
#initialize(lbrace:, statements:, location:, comments: []) ⇒ ENDBlock
Returns a new instance of ENDBlock.
229 230 231 232 233 234 |
# File 'lib/syntax_tree/node.rb', line 229 def initialize(lbrace:, statements:, location:, comments: []) @lbrace = lbrace @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
227 228 229 |
# File 'lib/syntax_tree/node.rb', line 227 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that is seen after the keyword
221 222 223 |
# File 'lib/syntax_tree/node.rb', line 221 def lbrace @lbrace end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
224 225 226 |
# File 'lib/syntax_tree/node.rb', line 224 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
236 237 238 |
# File 'lib/syntax_tree/node.rb', line 236 def accept(visitor) visitor.visit_END(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
240 241 242 |
# File 'lib/syntax_tree/node.rb', line 240 def child_nodes [lbrace, statements] end |
#deconstruct_keys(keys) ⇒ Object
246 247 248 249 250 251 252 253 |
# File 'lib/syntax_tree/node.rb', line 246 def deconstruct_keys(keys) { lbrace: lbrace, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/syntax_tree/node.rb', line 255 def format(q) q.group do q.text("END ") q.format(lbrace) q.indent do q.breakable q.format(statements) end q.breakable q.text("}") end end |