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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of Ident.



4576
4577
4578
4579
4580
# File 'lib/syntax_tree/node.rb', line 4576

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



4574
4575
4576
# File 'lib/syntax_tree/node.rb', line 4574

def comments
  @comments
end

#valueObject (readonly)

String

the value of the identifier



4571
4572
4573
# File 'lib/syntax_tree/node.rb', line 4571

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



4582
4583
4584
# File 'lib/syntax_tree/node.rb', line 4582

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

#child_nodesObject Also known as: deconstruct



4586
4587
4588
# File 'lib/syntax_tree/node.rb', line 4586

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



4592
4593
4594
# File 'lib/syntax_tree/node.rb', line 4592

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

#format(q) ⇒ Object



4596
4597
4598
# File 'lib/syntax_tree/node.rb', line 4596

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