Class: SyntaxTree::ConstRef

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

Overview

ConstRef represents the name of the constant being used in a class or module declaration.

class Container
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstRef.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3924
3925
3926
# File 'lib/syntax_tree.rb', line 3924

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



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

def location
  @location
end

Instance Method Details

#child_nodesObject



3938
3939
3940
# File 'lib/syntax_tree.rb', line 3938

def child_nodes
  [constant]
end

#format(q) ⇒ Object



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

def format(q)
  q.format(constant)
end

#pretty_print(q) ⇒ Object



3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
# File 'lib/syntax_tree.rb', line 3946

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

    q.breakable
    q.pp(constant)

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

#to_json(*opts) ⇒ Object



3957
3958
3959
3960
3961
3962
3963
3964
# File 'lib/syntax_tree.rb', line 3957

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