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

Returns a new instance of TopConstField.



11826
11827
11828
11829
11830
# File 'lib/syntax_tree.rb', line 11826

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



11824
11825
11826
# File 'lib/syntax_tree.rb', line 11824

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being assigned



11818
11819
11820
# File 'lib/syntax_tree.rb', line 11818

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



11821
11822
11823
# File 'lib/syntax_tree.rb', line 11821

def location
  @location
end

Instance Method Details

#child_nodesObject



11832
11833
11834
# File 'lib/syntax_tree.rb', line 11832

def child_nodes
  [constant]
end

#format(q) ⇒ Object



11836
11837
11838
11839
# File 'lib/syntax_tree.rb', line 11836

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

#pretty_print(q) ⇒ Object



11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
# File 'lib/syntax_tree.rb', line 11841

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



11852
11853
11854
11855
11856
11857
11858
11859
# File 'lib/syntax_tree.rb', line 11852

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