Class: SyntaxTree::PinnedBegin
Overview
PinnedBegin represents a pinning a nested statement within pattern matching.
case value
in ^(statement)
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#statement ⇒ Object
readonly
- untyped
-
the expression being pinned.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statement:, location:, comments: []) ⇒ PinnedBegin
constructor
A new instance of PinnedBegin.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statement:, location:, comments: []) ⇒ PinnedBegin
Returns a new instance of PinnedBegin.
1798 1799 1800 1801 1802 |
# File 'lib/syntax_tree/node.rb', line 1798 def initialize(statement:, location:, comments: []) @statement = statement @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1796 1797 1798 |
# File 'lib/syntax_tree/node.rb', line 1796 def comments @comments end |
#statement ⇒ Object (readonly)
- untyped
-
the expression being pinned
1793 1794 1795 |
# File 'lib/syntax_tree/node.rb', line 1793 def statement @statement end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
1804 1805 1806 |
# File 'lib/syntax_tree/node.rb', line 1804 def child_nodes [statement] end |
#deconstruct_keys(keys) ⇒ Object
1810 1811 1812 |
# File 'lib/syntax_tree/node.rb', line 1810 def deconstruct_keys(keys) { statement: statement, location: location, comments: comments } end |
#format(q) ⇒ Object
1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 |
# File 'lib/syntax_tree/node.rb', line 1814 def format(q) q.group do q.text("^(") q.nest(1) do q.indent do q.breakable("") q.format(statement) end q.breakable("") q.text(")") end end end |
#pretty_print(q) ⇒ Object
1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 |
# File 'lib/syntax_tree/node.rb', line 1828 def pretty_print(q) q.group(2, "(", ")") do q.text("pinned_begin") q.breakable q.pp(statement) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
1839 1840 1841 1842 1843 1844 1845 1846 |
# File 'lib/syntax_tree/node.rb', line 1839 def to_json(*opts) { type: :pinned_begin, stmt: statement, loc: location, cmts: comments }.to_json(*opts) end |