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:) ⇒ TopConstRef

Returns a new instance of TopConstRef.



10707
10708
10709
10710
10711
# File 'lib/syntax_tree/node.rb', line 10707

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10705
10706
10707
# File 'lib/syntax_tree/node.rb', line 10705

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being referenced



10702
10703
10704
# File 'lib/syntax_tree/node.rb', line 10702

def constant
  @constant
end

Instance Method Details

#===(other) ⇒ Object



10743
10744
10745
# File 'lib/syntax_tree/node.rb', line 10743

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

#accept(visitor) ⇒ Object



10713
10714
10715
# File 'lib/syntax_tree/node.rb', line 10713

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

#child_nodesObject Also known as: deconstruct



10717
10718
10719
# File 'lib/syntax_tree/node.rb', line 10717

def child_nodes
  [constant]
end

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



10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
# File 'lib/syntax_tree/node.rb', line 10721

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



10734
10735
10736
# File 'lib/syntax_tree/node.rb', line 10734

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

#format(q) ⇒ Object



10738
10739
10740
10741
# File 'lib/syntax_tree/node.rb', line 10738

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