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 | Field | Ident | MLHSParen | VarField] the parts of the left-hand side of a multiple assignment.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, comma: false, location:, comments: []) ⇒ MLHS
constructor
A new instance of MLHS.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(parts:, comma: false, location:, comments: []) ⇒ MLHS
Returns a new instance of MLHS.
6306 6307 6308 6309 6310 6311 |
# File 'lib/syntax_tree/node.rb', line 6306 def initialize(parts:, comma: false, location:, comments: []) @parts = parts @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
6301 6302 6303 |
# File 'lib/syntax_tree/node.rb', line 6301 def comma @comma end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6304 6305 6306 |
# File 'lib/syntax_tree/node.rb', line 6304 def comments @comments end |
#parts ⇒ Object (readonly)
Array[ARefField | ArgStar | Field | Ident | MLHSParen | VarField] the parts of the left-hand side of a multiple assignment
6296 6297 6298 |
# File 'lib/syntax_tree/node.rb', line 6296 def parts @parts end |
Instance Method Details
#accept(visitor) ⇒ Object
6313 6314 6315 |
# File 'lib/syntax_tree/node.rb', line 6313 def accept(visitor) visitor.visit_mlhs(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6317 6318 6319 |
# File 'lib/syntax_tree/node.rb', line 6317 def child_nodes parts end |
#deconstruct_keys(_keys) ⇒ Object
6323 6324 6325 |
# File 'lib/syntax_tree/node.rb', line 6323 def deconstruct_keys(_keys) { parts: parts, location: location, comma: comma, comments: comments } end |
#format(q) ⇒ Object
6327 6328 6329 6330 |
# File 'lib/syntax_tree/node.rb', line 6327 def format(q) q.seplist(parts) { |part| q.format(part) } q.text(",") if comma end |