class SyntaxTree::BEGINBlock
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.
Attributes
lbrace[R]
LBrace
-
the left brace that is seen after the keyword
statements[R]
Statements
-
the expressions to be executed
Public Class Methods
new(lbrace:, statements:, location:)
click to toggle source
# File lib/syntax_tree/node.rb, line 185 def initialize(lbrace:, statements:, location:) @lbrace = lbrace @statements = statements @location = location @comments = [] end
Public Instance Methods
===(other)
click to toggle source
# File lib/syntax_tree/node.rb, line 236 def ===(other) other.is_a?(BEGINBlock) && lbrace === other.lbrace && statements === other.statements end
accept(visitor)
click to toggle source
# File lib/syntax_tree/node.rb, line 192 def accept(visitor) visitor.visit_BEGIN(self) end
child_nodes()
click to toggle source
# File lib/syntax_tree/node.rb, line 196 def child_nodes [lbrace, statements] end
Also aliased as: deconstruct
copy(lbrace: nil, statements: nil, location: nil)
click to toggle source
# File lib/syntax_tree/node.rb, line 200 def copy(lbrace: nil, statements: nil, location: nil) node = BEGINBlock.new( lbrace: lbrace || self.lbrace, statements: statements || self.statements, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
deconstruct_keys(_keys)
click to toggle source
# File lib/syntax_tree/node.rb, line 214 def deconstruct_keys(_keys) { lbrace: lbrace, statements: statements, location: location, comments: comments } end
format(q)
click to toggle source
# File lib/syntax_tree/node.rb, line 223 def format(q) q.group do q.text("BEGIN ") q.format(lbrace) q.indent do q.breakable_space q.format(statements) end q.breakable_space q.text("}") end end