Class: SyntaxTree::Ident
Overview
Ident represents an identifier anywhere in code. It can represent a very large number of things, depending on where it is in the syntax tree.
value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the value of the identifier.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Ident
constructor
A new instance of Ident.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Ident
Returns a new instance of Ident.
5729 5730 5731 5732 5733 |
# File 'lib/syntax_tree/node.rb', line 5729 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
5727 5728 5729 |
# File 'lib/syntax_tree/node.rb', line 5727 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the value of the identifier
5724 5725 5726 |
# File 'lib/syntax_tree/node.rb', line 5724 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
5735 5736 5737 |
# File 'lib/syntax_tree/node.rb', line 5735 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
5741 5742 5743 |
# File 'lib/syntax_tree/node.rb', line 5741 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
5745 5746 5747 |
# File 'lib/syntax_tree/node.rb', line 5745 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 |
# File 'lib/syntax_tree/node.rb', line 5749 def pretty_print(q) q.group(2, "(", ")") do q.text("ident") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
5760 5761 5762 5763 5764 5765 5766 5767 |
# File 'lib/syntax_tree/node.rb', line 5760 def to_json(*opts) { type: :ident, value: value.force_encoding("UTF-8"), loc: location, cmts: comments }.to_json(*opts) end |