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.



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

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



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

def comments
  @comments
end

#valueObject (readonly)

String

the value of the identifier



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

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

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