Class: SyntaxTree::ConstRef

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

Overview

ConstRef represents the name of the constant being used in a class or module declaration.

class Container
end

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

Returns a new instance of ConstRef.



4017
4018
4019
4020
4021
# File 'lib/syntax_tree/node.rb', line 4017

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



4015
4016
4017
# File 'lib/syntax_tree/node.rb', line 4015

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



4012
4013
4014
# File 'lib/syntax_tree/node.rb', line 4012

def constant
  @constant
end

Instance Method Details

#===(other) ⇒ Object



4052
4053
4054
# File 'lib/syntax_tree/node.rb', line 4052

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

#accept(visitor) ⇒ Object



4023
4024
4025
# File 'lib/syntax_tree/node.rb', line 4023

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

#child_nodesObject Also known as: deconstruct



4027
4028
4029
# File 'lib/syntax_tree/node.rb', line 4027

def child_nodes
  [constant]
end

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



4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
# File 'lib/syntax_tree/node.rb', line 4031

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

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

#deconstruct_keys(_keys) ⇒ Object



4044
4045
4046
# File 'lib/syntax_tree/node.rb', line 4044

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

#format(q) ⇒ Object



4048
4049
4050
# File 'lib/syntax_tree/node.rb', line 4048

def format(q)
  q.format(constant)
end