Class: SyntaxTree::MLHSParen
Overview
MLHSParen represents parentheses being used to destruct values in a multiple assignment on the left hand side.
(left, right) = value
Instance Attribute Summary collapse
-
#comma ⇒ Object
- boolean
-
whether or not there is a trailing comma at the end of this list, which impacts destructuring.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#contents ⇒ Object
readonly
- MLHS | MLHSParen
-
the contents inside of the parentheses.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(contents:, comma: false, location:, comments: []) ⇒ MLHSParen
constructor
A new instance of MLHSParen.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(contents:, comma: false, location:, comments: []) ⇒ MLHSParen
Returns a new instance of MLHSParen.
6392 6393 6394 6395 6396 6397 |
# File 'lib/syntax_tree/node.rb', line 6392 def initialize(contents:, comma: false, location:, comments: []) @contents = contents @comma = comma @location = location @comments = comments end |
Instance Attribute Details
#comma ⇒ Object
- boolean
-
whether or not there is a trailing comma at the end of this
list, which impacts destructuring. It’s an attr_accessor so that while the syntax tree is being built it can be set by its parent node
6387 6388 6389 |
# File 'lib/syntax_tree/node.rb', line 6387 def comma @comma end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6390 6391 6392 |
# File 'lib/syntax_tree/node.rb', line 6390 def comments @comments end |
#contents ⇒ Object (readonly)
- MLHS | MLHSParen
-
the contents inside of the parentheses
6382 6383 6384 |
# File 'lib/syntax_tree/node.rb', line 6382 def contents @contents end |
Instance Method Details
#accept(visitor) ⇒ Object
6399 6400 6401 |
# File 'lib/syntax_tree/node.rb', line 6399 def accept(visitor) visitor.visit_mlhs_paren(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6403 6404 6405 |
# File 'lib/syntax_tree/node.rb', line 6403 def child_nodes [contents] end |
#deconstruct_keys(_keys) ⇒ Object
6409 6410 6411 |
# File 'lib/syntax_tree/node.rb', line 6409 def deconstruct_keys(_keys) { contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 |
# File 'lib/syntax_tree/node.rb', line 6413 def format(q) parent = q.parent if parent.is_a?(MAssign) || parent.is_a?(MLHSParen) q.format(contents) q.text(",") if comma else q.group(0, "(", ")") do q.indent do q.breakable("") q.format(contents) end q.text(",") if comma q.breakable("") end end end |