Class: SyntaxTree::TopConstRef

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

Overview

TopConstRef is very similar to TopConstField except that it is not involved in an assignment.

::Constant

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(constant:, location:, comments: []) ⇒ TopConstRef

Returns a new instance of TopConstRef.



8838
8839
8840
8841
8842
# File 'lib/syntax_tree/node.rb', line 8838

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8836
8837
8838
# File 'lib/syntax_tree/node.rb', line 8836

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being referenced



8833
8834
8835
# File 'lib/syntax_tree/node.rb', line 8833

def constant
  @constant
end

Instance Method Details

#accept(visitor) ⇒ Object



8844
8845
8846
# File 'lib/syntax_tree/node.rb', line 8844

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

#child_nodesObject Also known as: deconstruct



8848
8849
8850
# File 'lib/syntax_tree/node.rb', line 8848

def child_nodes
  [constant]
end

#deconstruct_keys(_keys) ⇒ Object



8854
8855
8856
# File 'lib/syntax_tree/node.rb', line 8854

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

#format(q) ⇒ Object



8858
8859
8860
8861
# File 'lib/syntax_tree/node.rb', line 8858

def format(q)
  q.text("::")
  q.format(constant)
end