Class: SyntaxTree::MLHS
Overview
MLHS represents a list of values being destructured on the left-hand side of a multiple assignment.
first, second, third = 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.
-
#parts ⇒ Object
readonly
- Array[ ARefField | ArgStar | ConstPathField | Field | Ident | MLHSParen | TopConstField | VarField
-
] the parts of the left-hand side of a multiple assignment.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(parts: nil, location: nil, comma: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, location:, comma: false) ⇒ MLHS
constructor
A new instance of MLHS.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(parts:, location:, comma: false) ⇒ MLHS
Returns a new instance of MLHS.
7670 7671 7672 7673 7674 7675 |
# File 'lib/syntax_tree/node.rb', line 7670 def initialize(parts:, location:, comma: false) @parts = parts @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
7665 7666 7667 |
# File 'lib/syntax_tree/node.rb', line 7665 def comma @comma end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7668 7669 7670 |
# File 'lib/syntax_tree/node.rb', line 7668 def comments @comments end |
#parts ⇒ Object (readonly)
[
Array[
ARefField | ArgStar | ConstPathField | Field | Ident | MLHSParen |
TopConstField | VarField
]
] the parts of the left-hand side of a multiple assignment
7660 7661 7662 |
# File 'lib/syntax_tree/node.rb', line 7660 def parts @parts end |
Instance Method Details
#===(other) ⇒ Object
7708 7709 7710 7711 |
# File 'lib/syntax_tree/node.rb', line 7708 def ===(other) other.is_a?(MLHS) && ArrayMatch.call(parts, other.parts) && comma === other.comma end |
#accept(visitor) ⇒ Object
7677 7678 7679 |
# File 'lib/syntax_tree/node.rb', line 7677 def accept(visitor) visitor.visit_mlhs(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7681 7682 7683 |
# File 'lib/syntax_tree/node.rb', line 7681 def child_nodes parts end |
#copy(parts: nil, location: nil, comma: nil) ⇒ Object
7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 |
# File 'lib/syntax_tree/node.rb', line 7685 def copy(parts: nil, location: nil, comma: nil) node = MLHS.new( parts: parts || self.parts, location: location || self.location, comma: comma || self.comma ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
7699 7700 7701 |
# File 'lib/syntax_tree/node.rb', line 7699 def deconstruct_keys(_keys) { parts: parts, location: location, comma: comma, comments: comments } end |
#format(q) ⇒ Object
7703 7704 7705 7706 |
# File 'lib/syntax_tree/node.rb', line 7703 def format(q) q.seplist(parts) { |part| q.format(part) } q.text(",") if comma end |