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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstPathRef.



3649
3650
3651
3652
3653
3654
# File 'lib/syntax_tree/node.rb', line 3649

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



3647
3648
3649
# File 'lib/syntax_tree/node.rb', line 3647

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3641
3642
3643
# File 'lib/syntax_tree/node.rb', line 3641

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



3644
3645
3646
# File 'lib/syntax_tree/node.rb', line 3644

def location
  @location
end

#parentObject (readonly)

untyped

the source of the constant



3638
3639
3640
# File 'lib/syntax_tree/node.rb', line 3638

def parent
  @parent
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



3656
3657
3658
# File 'lib/syntax_tree/node.rb', line 3656

def child_nodes
  [parent, constant]
end

#deconstruct_keys(keys) ⇒ Object



3662
3663
3664
3665
3666
3667
3668
3669
# File 'lib/syntax_tree/node.rb', line 3662

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

#format(q) ⇒ Object



3671
3672
3673
3674
3675
# File 'lib/syntax_tree/node.rb', line 3671

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

#pretty_print(q) ⇒ Object



3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
# File 'lib/syntax_tree/node.rb', line 3677

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



3691
3692
3693
3694
3695
3696
3697
3698
3699
# File 'lib/syntax_tree/node.rb', line 3691

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