Class: SyntaxTree::ConstPathField

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

Overview

ConstPathField represents the child node of some kind of assignment. It represents when you’re assigning to a constant that is being referenced as a child of another variable.

object::Const = value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstPathField.



3795
3796
3797
3798
3799
3800
# File 'lib/syntax_tree.rb', line 3795

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



3793
3794
3795
# File 'lib/syntax_tree.rb', line 3793

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3787
3788
3789
# File 'lib/syntax_tree.rb', line 3787

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



3790
3791
3792
# File 'lib/syntax_tree.rb', line 3790

def location
  @location
end

#parentObject (readonly)

untyped

the source of the constant



3784
3785
3786
# File 'lib/syntax_tree.rb', line 3784

def parent
  @parent
end

Instance Method Details

#child_nodesObject



3802
3803
3804
# File 'lib/syntax_tree.rb', line 3802

def child_nodes
  [parent, constant]
end

#format(q) ⇒ Object



3806
3807
3808
3809
3810
# File 'lib/syntax_tree.rb', line 3806

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

#pretty_print(q) ⇒ Object



3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
# File 'lib/syntax_tree.rb', line 3812

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

    q.breakable
    q.pp(parent)

    q.breakable
    q.pp(constant)

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

#to_json(*opts) ⇒ Object



3826
3827
3828
3829
3830
3831
3832
3833
3834
# File 'lib/syntax_tree.rb', line 3826

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