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

Constructor Details

#initialize(constant:, location:) ⇒ ConstRef

Returns a new instance of ConstRef.



3946
3947
3948
3949
3950
# File 'lib/syntax_tree/node.rb', line 3946

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3944
3945
3946
# File 'lib/syntax_tree/node.rb', line 3944

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3941
3942
3943
# File 'lib/syntax_tree/node.rb', line 3941

def constant
  @constant
end

Instance Method Details

#===(other) ⇒ Object



3981
3982
3983
# File 'lib/syntax_tree/node.rb', line 3981

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

#accept(visitor) ⇒ Object



3952
3953
3954
# File 'lib/syntax_tree/node.rb', line 3952

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

#child_nodesObject Also known as: deconstruct



3956
3957
3958
# File 'lib/syntax_tree/node.rb', line 3956

def child_nodes
  [constant]
end

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



3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
# File 'lib/syntax_tree/node.rb', line 3960

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



3973
3974
3975
# File 'lib/syntax_tree/node.rb', line 3973

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

#format(q) ⇒ Object



3977
3978
3979
# File 'lib/syntax_tree/node.rb', line 3977

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