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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(lbrace:, statements:, location:, comments: []) ⇒ BEGINBlock
Returns a new instance of BEGINBlock.
149 150 151 152 153 154 |
# File 'lib/syntax_tree/node.rb', line 149 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
147 148 149 |
# File 'lib/syntax_tree/node.rb', line 147 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that is seen after the keyword
141 142 143 |
# File 'lib/syntax_tree/node.rb', line 141 def lbrace @lbrace end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
144 145 146 |
# File 'lib/syntax_tree/node.rb', line 144 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
156 157 158 |
# File 'lib/syntax_tree/node.rb', line 156 def accept(visitor) visitor.visit_BEGIN(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
160 161 162 |
# File 'lib/syntax_tree/node.rb', line 160 def child_nodes [lbrace, statements] end |
#deconstruct_keys(_keys) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/syntax_tree/node.rb', line 166 def deconstruct_keys(_keys) { lbrace: lbrace, statements: statements, location: location, comments: comments } end |
#format(q) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/syntax_tree/node.rb', line 175 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 |