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
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(bodystmt:, location:, comments: []) ⇒ Begin
constructor
A new instance of Begin.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(bodystmt:, location:, comments: []) ⇒ Begin
Returns a new instance of Begin.
1734 1735 1736 1737 1738 |
# File 'lib/syntax_tree/node.rb', line 1734 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
1729 1730 1731 |
# File 'lib/syntax_tree/node.rb', line 1729 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1732 1733 1734 |
# File 'lib/syntax_tree/node.rb', line 1732 def comments @comments end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
1740 1741 1742 |
# File 'lib/syntax_tree/node.rb', line 1740 def child_nodes [bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
1746 1747 1748 |
# File 'lib/syntax_tree/node.rb', line 1746 def deconstruct_keys(keys) { bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 |
# File 'lib/syntax_tree/node.rb', line 1750 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 |
#pretty_print(q) ⇒ Object
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 |
# File 'lib/syntax_tree/node.rb', line 1764 def pretty_print(q) q.group(2, "(", ")") do q.text("begin") q.breakable q.pp(bodystmt) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
1775 1776 1777 1778 1779 1780 1781 1782 |
# File 'lib/syntax_tree/node.rb', line 1775 def to_json(*opts) { type: :begin, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |