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

#pretty_print, #to_json

Constructor Details

#initialize(parent:, constant:, location:, comments: []) ⇒ ConstPathRef

Returns a new instance of ConstPathRef.



2868
2869
2870
2871
2872
2873
# File 'lib/syntax_tree/node.rb', line 2868

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2866
2867
2868
# File 'lib/syntax_tree/node.rb', line 2866

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



2863
2864
2865
# File 'lib/syntax_tree/node.rb', line 2863

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



2860
2861
2862
# File 'lib/syntax_tree/node.rb', line 2860

def parent
  @parent
end

Instance Method Details

#accept(visitor) ⇒ Object



2875
2876
2877
# File 'lib/syntax_tree/node.rb', line 2875

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

#child_nodesObject Also known as: deconstruct



2879
2880
2881
# File 'lib/syntax_tree/node.rb', line 2879

def child_nodes
  [parent, constant]
end

#deconstruct_keys(keys) ⇒ Object



2885
2886
2887
2888
2889
2890
2891
2892
# File 'lib/syntax_tree/node.rb', line 2885

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

#format(q) ⇒ Object



2894
2895
2896
2897
2898
# File 'lib/syntax_tree/node.rb', line 2894

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