Class: SyntaxTree::TopConstField

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

Overview

TopConstField is always the child node of some kind of assignment. It represents when you’re assigning to a constant that is being referenced at the top level.

::Constant = value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



11746
11747
11748
11749
11750
# File 'lib/syntax_tree.rb', line 11746

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



11744
11745
11746
# File 'lib/syntax_tree.rb', line 11744

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being assigned



11738
11739
11740
# File 'lib/syntax_tree.rb', line 11738

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



11741
11742
11743
# File 'lib/syntax_tree.rb', line 11741

def location
  @location
end

Instance Method Details

#child_nodesObject



11752
11753
11754
# File 'lib/syntax_tree.rb', line 11752

def child_nodes
  [constant]
end

#format(q) ⇒ Object



11756
11757
11758
11759
# File 'lib/syntax_tree.rb', line 11756

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

#pretty_print(q) ⇒ Object



11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
# File 'lib/syntax_tree.rb', line 11761

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

    q.breakable
    q.pp(constant)

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

#to_json(*opts) ⇒ Object



11772
11773
11774
11775
11776
11777
11778
11779
# File 'lib/syntax_tree.rb', line 11772

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