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.



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

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



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

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



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

def constant
  @constant
end

#parentObject (readonly)

Node

the source of the constant



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

def parent
  @parent
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [parent, constant]
end

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



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

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



3965
3966
3967
3968
3969
3970
3971
3972
# File 'lib/syntax_tree/node.rb', line 3965

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

#format(q) ⇒ Object



3974
3975
3976
3977
3978
# File 'lib/syntax_tree/node.rb', line 3974

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