Class: SyntaxTree::ConstPathRef

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

Overview

ConstPathRef represents referencing a constant by a path.

object::Const

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstPathRef.



3864
3865
3866
3867
3868
3869
# File 'lib/syntax_tree.rb', line 3864

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



3862
3863
3864
# File 'lib/syntax_tree.rb', line 3862

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3856
3857
3858
# File 'lib/syntax_tree.rb', line 3856

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



3859
3860
3861
# File 'lib/syntax_tree.rb', line 3859

def location
  @location
end

#parentObject (readonly)

untyped

the source of the constant



3853
3854
3855
# File 'lib/syntax_tree.rb', line 3853

def parent
  @parent
end

Instance Method Details

#child_nodesObject



3871
3872
3873
# File 'lib/syntax_tree.rb', line 3871

def child_nodes
  [parent, constant]
end

#format(q) ⇒ Object



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

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

#pretty_print(q) ⇒ Object



3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
# File 'lib/syntax_tree.rb', line 3881

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("const_path_ref")

    q.breakable
    q.pp(parent)

    q.breakable
    q.pp(constant)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



3895
3896
3897
3898
3899
3900
3901
3902
3903
# File 'lib/syntax_tree.rb', line 3895

def to_json(*opts)
  {
    type: :const_path_ref,
    parent: parent,
    constant: constant,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end