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



5308
5309
5310
5311
5312
# File 'lib/syntax_tree/node.rb', line 5308

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5306
5307
5308
# File 'lib/syntax_tree/node.rb', line 5306

def comments
  @comments
end

#valueObject (readonly)

String

the value of the identifier



5303
5304
5305
# File 'lib/syntax_tree/node.rb', line 5303

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



5314
5315
5316
# File 'lib/syntax_tree/node.rb', line 5314

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

#child_nodesObject Also known as: deconstruct



5318
5319
5320
# File 'lib/syntax_tree/node.rb', line 5318

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



5324
5325
5326
# File 'lib/syntax_tree/node.rb', line 5324

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

#format(q) ⇒ Object



5328
5329
5330
# File 'lib/syntax_tree/node.rb', line 5328

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