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.
582 583 584 585 586 587 |
# File 'lib/syntax_tree.rb', line 582 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
580 581 582 |
# File 'lib/syntax_tree.rb', line 580 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that is seen after the keyword
571 572 573 |
# File 'lib/syntax_tree.rb', line 571 def lbrace @lbrace end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
577 578 579 |
# File 'lib/syntax_tree.rb', line 577 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
574 575 576 |
# File 'lib/syntax_tree.rb', line 574 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
589 590 591 |
# File 'lib/syntax_tree.rb', line 589 def child_nodes [lbrace, statements] end |
#format(q) ⇒ Object
593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/syntax_tree.rb', line 593 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
606 607 608 609 610 611 612 613 614 615 |
# File 'lib/syntax_tree.rb', line 606 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
617 618 619 620 621 622 623 624 625 |
# File 'lib/syntax_tree.rb', line 617 def to_json(*opts) { type: :END, lbrace: lbrace, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |