Class: SyntaxTree::ConstRef

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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



3718
3719
3720
3721
3722
# File 'lib/syntax_tree/node.rb', line 3718

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



3716
3717
3718
# File 'lib/syntax_tree/node.rb', line 3716

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3710
3711
3712
# File 'lib/syntax_tree/node.rb', line 3710

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



3713
3714
3715
# File 'lib/syntax_tree/node.rb', line 3713

def location
  @location
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



3724
3725
3726
# File 'lib/syntax_tree/node.rb', line 3724

def child_nodes
  [constant]
end

#deconstruct_keys(keys) ⇒ Object



3730
3731
3732
# File 'lib/syntax_tree/node.rb', line 3730

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

#format(q) ⇒ Object



3734
3735
3736
# File 'lib/syntax_tree/node.rb', line 3734

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

#pretty_print(q) ⇒ Object



3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
# File 'lib/syntax_tree/node.rb', line 3738

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



3749
3750
3751
3752
3753
3754
3755
3756
# File 'lib/syntax_tree/node.rb', line 3749

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