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
Constructor Details
#initialize(lparen:, contents:, location:, comments: []) ⇒ Paren
Returns a new instance of Paren.
6179 6180 6181 6182 6183 6184 |
# File 'lib/syntax_tree/node.rb', line 6179 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
6177 6178 6179 |
# File 'lib/syntax_tree/node.rb', line 6177 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | untyped
-
the expression inside the parentheses
6174 6175 6176 |
# File 'lib/syntax_tree/node.rb', line 6174 def contents @contents end |
#lparen ⇒ Object (readonly)
- LParen
-
the left parenthesis that opened this statement
6171 6172 6173 |
# File 'lib/syntax_tree/node.rb', line 6171 def lparen @lparen end |
Instance Method Details
#accept(visitor) ⇒ Object
6186 6187 6188 |
# File 'lib/syntax_tree/node.rb', line 6186 def accept(visitor) visitor.visit_paren(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6190 6191 6192 |
# File 'lib/syntax_tree/node.rb', line 6190 def child_nodes [lparen, contents] end |
#deconstruct_keys(keys) ⇒ Object
6196 6197 6198 6199 6200 6201 6202 6203 |
# File 'lib/syntax_tree/node.rb', line 6196 def deconstruct_keys(keys) { lparen: lparen, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 |
# File 'lib/syntax_tree/node.rb', line 6205 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 |