Class: SyntaxTree::ENDBlock
- Inherits:
-
Object
- Object
- SyntaxTree::ENDBlock
- Defined in:
- lib/syntax_tree.rb
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
- #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.
569 570 571 572 573 574 |
# File 'lib/syntax_tree.rb', line 569 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
567 568 569 |
# File 'lib/syntax_tree.rb', line 567 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that is seen after the keyword
558 559 560 |
# File 'lib/syntax_tree.rb', line 558 def lbrace @lbrace end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
564 565 566 |
# File 'lib/syntax_tree.rb', line 564 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
561 562 563 |
# File 'lib/syntax_tree.rb', line 561 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
576 577 578 |
# File 'lib/syntax_tree.rb', line 576 def child_nodes [lbrace, statements] end |
#format(q) ⇒ Object
580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/syntax_tree.rb', line 580 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
593 594 595 596 597 598 599 600 601 602 |
# File 'lib/syntax_tree.rb', line 593 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
604 605 606 607 608 609 610 611 612 |
# File 'lib/syntax_tree.rb', line 604 def to_json(*opts) { type: :END, lbrace: lbrace, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |