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
(also: #comma?)
- 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
7820 7821 7822 7823 7824 7825 |
# File 'lib/syntax_tree.rb', line 7820 def initialize(parts:, comma: false, location:, comments: []) @parts = parts @comma = comma @location = location @comments = comments end |
Instance Attribute Details
#comma ⇒ Object Also known as: comma?
- 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
7811 7812 7813 |
# File 'lib/syntax_tree.rb', line 7811 def comma @comma end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7818 7819 7820 |
# File 'lib/syntax_tree.rb', line 7818 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
7815 7816 7817 |
# File 'lib/syntax_tree.rb', line 7815 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
7806 7807 7808 |
# File 'lib/syntax_tree.rb', line 7806 def parts @parts end |
Instance Method Details
#child_nodes ⇒ Object
7827 7828 7829 |
# File 'lib/syntax_tree.rb', line 7827 def child_nodes parts end |
#format(q) ⇒ Object
7831 7832 7833 |
# File 'lib/syntax_tree.rb', line 7831 def format(q) q.seplist(parts) { |part| q.format(part) } end |
#pretty_print(q) ⇒ Object
7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 |
# File 'lib/syntax_tree.rb', line 7835 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
7846 7847 7848 7849 7850 7851 7852 7853 7854 |
# File 'lib/syntax_tree.rb', line 7846 def to_json(*opts) { type: :mlhs, parts: parts, comma: comma, loc: location, cmts: comments }.to_json(*opts) end |