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



3921
3922
3923
3924
3925
# File 'lib/syntax_tree/node.rb', line 3921

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3919
3920
3921
# File 'lib/syntax_tree/node.rb', line 3919

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3916
3917
3918
# File 'lib/syntax_tree/node.rb', line 3916

def constant
  @constant
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



3927
3928
3929
# File 'lib/syntax_tree/node.rb', line 3927

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

#child_nodesObject Also known as: deconstruct



3931
3932
3933
# File 'lib/syntax_tree/node.rb', line 3931

def child_nodes
  [constant]
end

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



3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
# File 'lib/syntax_tree/node.rb', line 3935

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



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

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

#format(q) ⇒ Object



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

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