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.



4983
4984
4985
4986
4987
# File 'lib/syntax_tree/node.rb', line 4983

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



4981
4982
4983
# File 'lib/syntax_tree/node.rb', line 4981

def comments
  @comments
end

#valueObject (readonly)

String

the value of the identifier



4978
4979
4980
# File 'lib/syntax_tree/node.rb', line 4978

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



4989
4990
4991
# File 'lib/syntax_tree/node.rb', line 4989

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

#child_nodesObject Also known as: deconstruct



4993
4994
4995
# File 'lib/syntax_tree/node.rb', line 4993

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



4999
5000
5001
# File 'lib/syntax_tree/node.rb', line 4999

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

#format(q) ⇒ Object



5003
5004
5005
# File 'lib/syntax_tree/node.rb', line 5003

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