Class: SyntaxTree::MLHS
- Inherits:
-
Object
- Object
- SyntaxTree::MLHS
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#parts ⇒ Object
readonly
Array[ARefField | ArgStar | Field | Ident | MLHSParen | VarField] the parts of the left-hand side of a multiple assignment.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, comma: false, location:, comments: []) ⇒ MLHS
constructor
A new instance of MLHS.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(parts:, comma: false, location:, comments: []) ⇒ MLHS
Returns a new instance of MLHS.
8365 8366 8367 8368 8369 8370 |
# File 'lib/syntax_tree.rb', line 8365 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
8357 8358 8359 |
# File 'lib/syntax_tree.rb', line 8357 def comma @comma end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8363 8364 8365 |
# File 'lib/syntax_tree.rb', line 8363 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8360 8361 8362 |
# File 'lib/syntax_tree.rb', line 8360 def location @location end |
#parts ⇒ Object (readonly)
Array[ARefField | ArgStar | Field | Ident | MLHSParen | VarField] the parts of the left-hand side of a multiple assignment
8352 8353 8354 |
# File 'lib/syntax_tree.rb', line 8352 def parts @parts end |
Instance Method Details
#child_nodes ⇒ Object
8372 8373 8374 |
# File 'lib/syntax_tree.rb', line 8372 def child_nodes parts end |
#format(q) ⇒ Object
8376 8377 8378 8379 |
# File 'lib/syntax_tree.rb', line 8376 def format(q) q.seplist(parts) { |part| q.format(part) } q.text(",") if comma end |
#pretty_print(q) ⇒ Object
8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 |
# File 'lib/syntax_tree.rb', line 8381 def pretty_print(q) q.group(2, "(", ")") do q.text("mlhs") q.breakable q.group(2, "(", ")") { q.seplist(parts) { |part| q.pp(part) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
8392 8393 8394 8395 8396 8397 8398 8399 8400 |
# File 'lib/syntax_tree.rb', line 8392 def to_json(*opts) { type: :mlhs, parts: parts, comma: comma, loc: location, cmts: comments }.to_json(*opts) end |