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.



4002
4003
4004
4005
4006
# File 'lib/syntax_tree/node.rb', line 4002

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



4000
4001
4002
# File 'lib/syntax_tree/node.rb', line 4000

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3997
3998
3999
# File 'lib/syntax_tree/node.rb', line 3997

def constant
  @constant
end

Instance Method Details

#===(other) ⇒ Object



4037
4038
4039
# File 'lib/syntax_tree/node.rb', line 4037

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

#accept(visitor) ⇒ Object



4008
4009
4010
# File 'lib/syntax_tree/node.rb', line 4008

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [constant]
end

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



4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
# File 'lib/syntax_tree/node.rb', line 4016

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



4029
4030
4031
# File 'lib/syntax_tree/node.rb', line 4029

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

#format(q) ⇒ Object



4033
4034
4035
# File 'lib/syntax_tree/node.rb', line 4033

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