Class: SyntaxTree::Ident

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

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

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:, comments: []) ⇒ Ident

Returns a new instance of Ident.



5102
5103
5104
5105
5106
# File 'lib/syntax_tree/node.rb', line 5102

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



5100
5101
5102
# File 'lib/syntax_tree/node.rb', line 5100

def comments
  @comments
end

#value ⇒ Object (readonly)

[String] the value of the identifier



5097
5098
5099
# File 'lib/syntax_tree/node.rb', line 5097

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



5108
5109
5110
# File 'lib/syntax_tree/node.rb', line 5108

def accept(visitor)
  visitor.visit_ident(self)
end

#child_nodes ⇒ Object Also known as: deconstruct



5112
5113
5114
# File 'lib/syntax_tree/node.rb', line 5112

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



5118
5119
5120
# File 'lib/syntax_tree/node.rb', line 5118

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



5122
5123
5124
# File 'lib/syntax_tree/node.rb', line 5122

def format(q)
  q.text(value)
end