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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(contents: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(contents:, comma: false, location:) ⇒ MLHSParen
constructor
A new instance of MLHSParen.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(contents:, comma: false, location:) ⇒ MLHSParen
Returns a new instance of MLHSParen.
7608 7609 7610 7611 7612 7613 |
# File 'lib/syntax_tree/node.rb', line 7608 def initialize(contents:, comma: false, location:) @contents = contents @comma = comma @location = location @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
7603 7604 7605 |
# File 'lib/syntax_tree/node.rb', line 7603 def comma @comma end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7606 7607 7608 |
# File 'lib/syntax_tree/node.rb', line 7606 def comments @comments end |
#contents ⇒ Object (readonly)
- MLHS | MLHSParen
-
the contents inside of the parentheses
7598 7599 7600 |
# File 'lib/syntax_tree/node.rb', line 7598 def contents @contents end |
Instance Method Details
#===(other) ⇒ Object
7661 7662 7663 |
# File 'lib/syntax_tree/node.rb', line 7661 def ===(other) other.is_a?(MLHSParen) && contents === other.contents end |
#accept(visitor) ⇒ Object
7615 7616 7617 |
# File 'lib/syntax_tree/node.rb', line 7615 def accept(visitor) visitor.visit_mlhs_paren(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7619 7620 7621 |
# File 'lib/syntax_tree/node.rb', line 7619 def child_nodes [contents] end |
#copy(contents: nil, location: nil) ⇒ Object
7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 |
# File 'lib/syntax_tree/node.rb', line 7623 def copy(contents: nil, location: nil) node = MLHSParen.new( contents: contents || self.contents, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
7636 7637 7638 |
# File 'lib/syntax_tree/node.rb', line 7636 def deconstruct_keys(_keys) { contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 |
# File 'lib/syntax_tree/node.rb', line 7640 def format(q) parent = q.parent if parent.is_a?(MAssign) || parent.is_a?(MLHSParen) q.format(contents) q.text(",") if comma else q.text("(") q.group do q.indent do q.breakable_empty q.format(contents) end q.text(",") if comma q.breakable_empty end q.text(")") end end |