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.
1510 1511 1512 1513 1514 |
# File 'lib/syntax_tree/node.rb', line 1510 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
1505 1506 1507 |
# File 'lib/syntax_tree/node.rb', line 1505 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1508 1509 1510 |
# File 'lib/syntax_tree/node.rb', line 1508 def comments @comments end |
Instance Method Details
#accept(visitor) ⇒ Object
1516 1517 1518 |
# File 'lib/syntax_tree/node.rb', line 1516 def accept(visitor) visitor.visit_begin(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1520 1521 1522 |
# File 'lib/syntax_tree/node.rb', line 1520 def child_nodes [bodystmt] end |
#deconstruct_keys(_keys) ⇒ Object
1526 1527 1528 |
# File 'lib/syntax_tree/node.rb', line 1526 def deconstruct_keys(_keys) { bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 |
# File 'lib/syntax_tree/node.rb', line 1530 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 |