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

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstRef.



3601
3602
3603
3604
3605
# File 'lib/syntax_tree/node.rb', line 3601

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



3599
3600
3601
# File 'lib/syntax_tree/node.rb', line 3599

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3596
3597
3598
# File 'lib/syntax_tree/node.rb', line 3596

def constant
  @constant
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



3607
3608
3609
# File 'lib/syntax_tree/node.rb', line 3607

def child_nodes
  [constant]
end

#deconstruct_keys(keys) ⇒ Object



3613
3614
3615
# File 'lib/syntax_tree/node.rb', line 3613

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

#format(q) ⇒ Object



3617
3618
3619
# File 'lib/syntax_tree/node.rb', line 3617

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

#pretty_print(q) ⇒ Object



3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
# File 'lib/syntax_tree/node.rb', line 3621

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



3632
3633
3634
3635
3636
3637
3638
3639
# File 'lib/syntax_tree/node.rb', line 3632

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