Class: SyntaxTree::BEGINBlock
Overview
BEGINBlock represents the use of the BEGIN keyword, which hooks into the lifecycle of the interpreter. Whatever is inside the block will get executed when the program starts.
BEGIN {
}
Interestingly, the BEGIN 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: []) ⇒ BEGINBlock
constructor
A new instance of BEGINBlock.
Methods inherited from Node
Constructor Details
#initialize(lbrace:, statements:, location:, comments: []) ⇒ BEGINBlock
Returns a new instance of BEGINBlock.
111 112 113 114 115 116 |
# File 'lib/syntax_tree/node.rb', line 111 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
109 110 111 |
# File 'lib/syntax_tree/node.rb', line 109 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that is seen after the keyword
103 104 105 |
# File 'lib/syntax_tree/node.rb', line 103 def lbrace @lbrace end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
106 107 108 |
# File 'lib/syntax_tree/node.rb', line 106 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
118 119 120 |
# File 'lib/syntax_tree/node.rb', line 118 def accept(visitor) visitor.visit_BEGIN(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
122 123 124 |
# File 'lib/syntax_tree/node.rb', line 122 def child_nodes [lbrace, statements] end |
#deconstruct_keys(keys) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/syntax_tree/node.rb', line 128 def deconstruct_keys(keys) { lbrace: lbrace, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/syntax_tree/node.rb', line 137 def format(q) q.group do q.text("BEGIN ") q.format(lbrace) q.indent do q.breakable q.format(statements) end q.breakable q.text("}") end end |