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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(constant:, location:) ⇒ TopConstRef

Returns a new instance of TopConstRef.



10899
10900
10901
10902
10903
# File 'lib/syntax_tree/node.rb', line 10899

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10897
10898
10899
# File 'lib/syntax_tree/node.rb', line 10897

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being referenced



10894
10895
10896
# File 'lib/syntax_tree/node.rb', line 10894

def constant
  @constant
end

Instance Method Details

#===(other) ⇒ Object



10935
10936
10937
# File 'lib/syntax_tree/node.rb', line 10935

def ===(other)
  other.is_a?(TopConstRef) && constant === other.constant
end

#accept(visitor) ⇒ Object



10905
10906
10907
# File 'lib/syntax_tree/node.rb', line 10905

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

#child_nodesObject Also known as: deconstruct



10909
10910
10911
# File 'lib/syntax_tree/node.rb', line 10909

def child_nodes
  [constant]
end

#copy(constant: nil, location: nil) ⇒ Object



10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
# File 'lib/syntax_tree/node.rb', line 10913

def copy(constant: nil, location: nil)
  node =
    TopConstRef.new(
      constant: constant || self.constant,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



10926
10927
10928
# File 'lib/syntax_tree/node.rb', line 10926

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

#format(q) ⇒ Object



10930
10931
10932
10933
# File 'lib/syntax_tree/node.rb', line 10930

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