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

Constructor Details

#initialize(parent:, constant:, location:) ⇒ ConstPathRef

Returns a new instance of ConstPathRef.



3883
3884
3885
3886
3887
3888
# File 'lib/syntax_tree/node.rb', line 3883

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



3881
3882
3883
# File 'lib/syntax_tree/node.rb', line 3881

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3878
3879
3880
# File 'lib/syntax_tree/node.rb', line 3878

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



3875
3876
3877
# File 'lib/syntax_tree/node.rb', line 3875

def parent
  @parent
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



3890
3891
3892
# File 'lib/syntax_tree/node.rb', line 3890

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

#child_nodesObject Also known as: deconstruct



3894
3895
3896
# File 'lib/syntax_tree/node.rb', line 3894

def child_nodes
  [parent, constant]
end

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



3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
# File 'lib/syntax_tree/node.rb', line 3898

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



3912
3913
3914
3915
3916
3917
3918
3919
# File 'lib/syntax_tree/node.rb', line 3912

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

#format(q) ⇒ Object



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

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