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

#pretty_print, #to_json

Constructor Details

#initialize(constant:, location:, comments: []) ⇒ TopConstRef

Returns a new instance of TopConstRef.



8571
8572
8573
8574
8575
# File 'lib/syntax_tree/node.rb', line 8571

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



8569
8570
8571
# File 'lib/syntax_tree/node.rb', line 8569

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being referenced



8566
8567
8568
# File 'lib/syntax_tree/node.rb', line 8566

def constant
  @constant
end

Instance Method Details

#accept(visitor) ⇒ Object



8577
8578
8579
# File 'lib/syntax_tree/node.rb', line 8577

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

#child_nodesObject Also known as: deconstruct



8581
8582
8583
# File 'lib/syntax_tree/node.rb', line 8581

def child_nodes
  [constant]
end

#deconstruct_keys(keys) ⇒ Object



8587
8588
8589
# File 'lib/syntax_tree/node.rb', line 8587

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

#format(q) ⇒ Object



8591
8592
8593
8594
# File 'lib/syntax_tree/node.rb', line 8591

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