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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lbrace:, statements:, location:, comments: []) ⇒ ENDBlock
constructor
A new instance of ENDBlock.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(lbrace:, statements:, location:, comments: []) ⇒ ENDBlock
Returns a new instance of ENDBlock.
242 243 244 245 246 247 |
# File 'lib/syntax_tree/node.rb', line 242 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
240 241 242 |
# File 'lib/syntax_tree/node.rb', line 240 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that is seen after the keyword
231 232 233 |
# File 'lib/syntax_tree/node.rb', line 231 def lbrace @lbrace end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
237 238 239 |
# File 'lib/syntax_tree/node.rb', line 237 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
234 235 236 |
# File 'lib/syntax_tree/node.rb', line 234 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
249 250 251 |
# File 'lib/syntax_tree/node.rb', line 249 def child_nodes [lbrace, statements] end |
#deconstruct_keys(keys) ⇒ Object
255 256 257 258 259 260 261 262 |
# File 'lib/syntax_tree/node.rb', line 255 def deconstruct_keys(keys) { lbrace: lbrace, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/syntax_tree/node.rb', line 264 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 |
#pretty_print(q) ⇒ Object
277 278 279 280 281 282 283 284 285 286 |
# File 'lib/syntax_tree/node.rb', line 277 def pretty_print(q) q.group(2, "(", ")") do q.text("END") q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
288 289 290 291 292 293 294 295 296 |
# File 'lib/syntax_tree/node.rb', line 288 def to_json(*opts) { type: :END, lbrace: lbrace, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |