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.
-
#location ⇒ Object
readonly
- Location
-
the location of this 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.
1794 1795 1796 1797 1798 |
# File 'lib/syntax_tree/node.rb', line 1794 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
1786 1787 1788 |
# File 'lib/syntax_tree/node.rb', line 1786 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1792 1793 1794 |
# File 'lib/syntax_tree/node.rb', line 1792 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
1789 1790 1791 |
# File 'lib/syntax_tree/node.rb', line 1789 def location @location end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
1800 1801 1802 |
# File 'lib/syntax_tree/node.rb', line 1800 def child_nodes [bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
1806 1807 1808 |
# File 'lib/syntax_tree/node.rb', line 1806 def deconstruct_keys(keys) { bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 |
# File 'lib/syntax_tree/node.rb', line 1810 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
1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 |
# File 'lib/syntax_tree/node.rb', line 1824 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
1835 1836 1837 1838 1839 1840 1841 1842 |
# File 'lib/syntax_tree/node.rb', line 1835 def to_json(*opts) { type: :begin, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |