Class: SyntaxTree::ExcessedComma
Overview
ExcessedComma represents a trailing comma in a list of block parameters. It changes the block parameters such that they will destructure.
[[1, 2, 3], [2, 3, 4]].each do |first, second,|
end
In the above example, an ExcessedComma node would appear in the third position of the Params node that is used to declare that block. The third position typically represents a rest-type parameter, but in this case is used to indicate that a trailing comma was used.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the comma.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ ExcessedComma
constructor
A new instance of ExcessedComma.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ ExcessedComma
Returns a new instance of ExcessedComma.
4841 4842 4843 4844 4845 |
# File 'lib/syntax_tree/node.rb', line 4841 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4839 4840 4841 |
# File 'lib/syntax_tree/node.rb', line 4839 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the comma
4836 4837 4838 |
# File 'lib/syntax_tree/node.rb', line 4836 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
4847 4848 4849 |
# File 'lib/syntax_tree/node.rb', line 4847 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
4853 4854 4855 |
# File 'lib/syntax_tree/node.rb', line 4853 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
4857 4858 4859 |
# File 'lib/syntax_tree/node.rb', line 4857 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 |
# File 'lib/syntax_tree/node.rb', line 4861 def pretty_print(q) q.group(2, "(", ")") do q.text("excessed_comma") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
4872 4873 4874 4875 4876 4877 4878 4879 |
# File 'lib/syntax_tree/node.rb', line 4872 def to_json(*opts) { type: :excessed_comma, value: value, loc: location, cmts: comments }.to_json(*opts) end |