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.
7190 7191 7192 7193 7194 7195 |
# File 'lib/syntax_tree/node.rb', line 7190 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
7188 7189 7190 |
# File 'lib/syntax_tree/node.rb', line 7188 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | untyped
-
the expression inside the parentheses
7185 7186 7187 |
# File 'lib/syntax_tree/node.rb', line 7185 def contents @contents end |
#lparen ⇒ Object (readonly)
- LParen
-
the left parenthesis that opened this statement
7182 7183 7184 |
# File 'lib/syntax_tree/node.rb', line 7182 def lparen @lparen end |
Instance Method Details
#accept(visitor) ⇒ Object
7197 7198 7199 |
# File 'lib/syntax_tree/node.rb', line 7197 def accept(visitor) visitor.visit_paren(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7201 7202 7203 |
# File 'lib/syntax_tree/node.rb', line 7201 def child_nodes [lparen, contents] end |
#deconstruct_keys(_keys) ⇒ Object
7207 7208 7209 7210 7211 7212 7213 7214 |
# File 'lib/syntax_tree/node.rb', line 7207 def deconstruct_keys(_keys) { lparen: lparen, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 |
# File 'lib/syntax_tree/node.rb', line 7216 def format(q) q.group do q.format(lparen) if contents && (!contents.is_a?(Params) || !contents.empty?) q.indent do q.breakable_empty q.format(contents) end end q.breakable_empty q.text(")") end end |