Class: SyntaxTree::Begin
Overview
Begin represents a begin..end chain.
begin
value
end
Instance Attribute Summary collapse
-
#bodystmt ⇒ Object
readonly
- BodyStmt
-
the bodystmt that contains the contents of this begin block.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(bodystmt:, location:, comments: []) ⇒ Begin
constructor
A new instance of Begin.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(bodystmt:, location:, comments: []) ⇒ Begin
Returns a new instance of Begin.
1522 1523 1524 1525 1526 |
# File 'lib/syntax_tree/node.rb', line 1522 def initialize(bodystmt:, location:, comments: []) @bodystmt = bodystmt @location = location @comments = comments end |
Instance Attribute Details
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the bodystmt that contains the contents of this begin block
1517 1518 1519 |
# File 'lib/syntax_tree/node.rb', line 1517 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1520 1521 1522 |
# File 'lib/syntax_tree/node.rb', line 1520 def comments @comments end |
Instance Method Details
#accept(visitor) ⇒ Object
1528 1529 1530 |
# File 'lib/syntax_tree/node.rb', line 1528 def accept(visitor) visitor.visit_begin(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1532 1533 1534 |
# File 'lib/syntax_tree/node.rb', line 1532 def child_nodes [bodystmt] end |
#deconstruct_keys(_keys) ⇒ Object
1538 1539 1540 |
# File 'lib/syntax_tree/node.rb', line 1538 def deconstruct_keys(_keys) { bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 |
# File 'lib/syntax_tree/node.rb', line 1542 def format(q) q.text("begin") unless bodystmt.empty? q.indent do q.breakable(force: true) unless bodystmt.statements.empty? q.format(bodystmt) end end q.breakable(force: true) q.text("end") end |