Class: SyntaxTree::Label
Overview
Label represents the use of an identifier to associate with an object. You can find it in a hash key, as in:
{ key: value }
In this case “key:” would be the body of the label. You can also find it in pattern matching, as in:
case value
in key:
end
In this case “key:” would be the body of the label.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the value of the label.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Label
constructor
A new instance of Label.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Label
Returns a new instance of Label.
6541 6542 6543 6544 6545 |
# File 'lib/syntax_tree/node.rb', line 6541 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
6539 6540 6541 |
# File 'lib/syntax_tree/node.rb', line 6539 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the value of the label
6536 6537 6538 |
# File 'lib/syntax_tree/node.rb', line 6536 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
6547 6548 6549 |
# File 'lib/syntax_tree/node.rb', line 6547 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
6553 6554 6555 |
# File 'lib/syntax_tree/node.rb', line 6553 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
6557 6558 6559 |
# File 'lib/syntax_tree/node.rb', line 6557 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 |
# File 'lib/syntax_tree/node.rb', line 6561 def pretty_print(q) q.group(2, "(", ")") do q.text("label") q.breakable q.text(":") q.text(value[0...-1]) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
6573 6574 6575 6576 6577 |
# File 'lib/syntax_tree/node.rb', line 6573 def to_json(*opts) { type: :label, value: value, loc: location, cmts: comments }.to_json( *opts ) end |