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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:) ⇒ Label
constructor
A new instance of Label.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ Label
Returns a new instance of Label.
7032 7033 7034 7035 7036 |
# File 'lib/syntax_tree/node.rb', line 7032 def initialize(value:, location:) @value = value @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7030 7031 7032 |
# File 'lib/syntax_tree/node.rb', line 7030 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the value of the label
7027 7028 7029 |
# File 'lib/syntax_tree/node.rb', line 7027 def value @value end |
Instance Method Details
#===(other) ⇒ Object
7067 7068 7069 |
# File 'lib/syntax_tree/node.rb', line 7067 def ===(other) other.is_a?(Label) && value === other.value end |
#accept(visitor) ⇒ Object
7038 7039 7040 |
# File 'lib/syntax_tree/node.rb', line 7038 def accept(visitor) visitor.visit_label(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7042 7043 7044 |
# File 'lib/syntax_tree/node.rb', line 7042 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 |
# File 'lib/syntax_tree/node.rb', line 7046 def copy(value: nil, location: nil) node = Label.new( value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
7059 7060 7061 |
# File 'lib/syntax_tree/node.rb', line 7059 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
7063 7064 7065 |
# File 'lib/syntax_tree/node.rb', line 7063 def format(q) q.text(value) end |