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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(contents:, comma: false, location:) ⇒ MLHSParen
Returns a new instance of MLHSParen.
7706 7707 7708 7709 7710 7711 |
# File 'lib/syntax_tree/node.rb', line 7706 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
7701 7702 7703 |
# File 'lib/syntax_tree/node.rb', line 7701 def comma @comma end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7704 7705 7706 |
# File 'lib/syntax_tree/node.rb', line 7704 def comments @comments end |
#contents ⇒ Object (readonly)
- MLHS | MLHSParen
-
the contents inside of the parentheses
7696 7697 7698 |
# File 'lib/syntax_tree/node.rb', line 7696 def contents @contents end |
Instance Method Details
#===(other) ⇒ Object
7759 7760 7761 |
# File 'lib/syntax_tree/node.rb', line 7759 def ===(other) other.is_a?(MLHSParen) && contents === other.contents end |
#accept(visitor) ⇒ Object
7713 7714 7715 |
# File 'lib/syntax_tree/node.rb', line 7713 def accept(visitor) visitor.visit_mlhs_paren(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7717 7718 7719 |
# File 'lib/syntax_tree/node.rb', line 7717 def child_nodes [contents] end |
#copy(contents: nil, location: nil) ⇒ Object
7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 |
# File 'lib/syntax_tree/node.rb', line 7721 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
7734 7735 7736 |
# File 'lib/syntax_tree/node.rb', line 7734 def deconstruct_keys(_keys) { contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 |
# File 'lib/syntax_tree/node.rb', line 7738 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 |