Class: SyntaxTree::Paren
Overview
Paren represents using balanced parentheses in a couple places in a Ruby program. In general parentheses can be used anywhere a Ruby expression can be used.
(1 + 2)
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#contents ⇒ Object
readonly
- nil | untyped
-
the expression inside the parentheses.
-
#lparen ⇒ Object
readonly
- LParen
-
the left parenthesis that opened this statement.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lparen:, contents:, location:, comments: []) ⇒ Paren
constructor
A new instance of Paren.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(lparen:, contents:, location:, comments: []) ⇒ Paren
Returns a new instance of Paren.
6822 6823 6824 6825 6826 6827 |
# File 'lib/syntax_tree/node.rb', line 6822 def initialize(lparen:, contents:, location:, comments: []) @lparen = lparen @contents = contents @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6820 6821 6822 |
# File 'lib/syntax_tree/node.rb', line 6820 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | untyped
-
the expression inside the parentheses
6817 6818 6819 |
# File 'lib/syntax_tree/node.rb', line 6817 def contents @contents end |
#lparen ⇒ Object (readonly)
- LParen
-
the left parenthesis that opened this statement
6814 6815 6816 |
# File 'lib/syntax_tree/node.rb', line 6814 def lparen @lparen end |
Instance Method Details
#accept(visitor) ⇒ Object
6829 6830 6831 |
# File 'lib/syntax_tree/node.rb', line 6829 def accept(visitor) visitor.visit_paren(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6833 6834 6835 |
# File 'lib/syntax_tree/node.rb', line 6833 def child_nodes [lparen, contents] end |
#deconstruct_keys(_keys) ⇒ Object
6839 6840 6841 6842 6843 6844 6845 6846 |
# File 'lib/syntax_tree/node.rb', line 6839 def deconstruct_keys(_keys) { lparen: lparen, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 |
# File 'lib/syntax_tree/node.rb', line 6848 def format(q) q.group do q.format(lparen) if contents && (!contents.is_a?(Params) || !contents.empty?) q.indent do q.breakable("") q.format(contents) end end q.breakable("") q.text(")") end end |