Class: SyntaxTree::ConstPathRef

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

Overview

ConstPathRef represents referencing a constant by a path.

object::Const

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(parent:, constant:, location:) ⇒ ConstPathRef

Returns a new instance of ConstPathRef.



3923
3924
3925
3926
3927
3928
# File 'lib/syntax_tree/node.rb', line 3923

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



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

def constant
  @constant
end

#parentObject (readonly)

Node

the source of the constant



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

def parent
  @parent
end

Instance Method Details

#===(other) ⇒ Object



3967
3968
3969
3970
# File 'lib/syntax_tree/node.rb', line 3967

def ===(other)
  other.is_a?(ConstPathRef) && parent === other.parent &&
    constant === other.constant
end

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



3934
3935
3936
# File 'lib/syntax_tree/node.rb', line 3934

def child_nodes
  [parent, constant]
end

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



3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
# File 'lib/syntax_tree/node.rb', line 3938

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

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

#deconstruct_keys(_keys) ⇒ Object



3952
3953
3954
3955
3956
3957
3958
3959
# File 'lib/syntax_tree/node.rb', line 3952

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

#format(q) ⇒ Object



3961
3962
3963
3964
3965
# File 'lib/syntax_tree/node.rb', line 3961

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