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.



11958
11959
11960
11961
11962
# File 'lib/syntax_tree.rb', line 11958

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



11956
11957
11958
# File 'lib/syntax_tree.rb', line 11956

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being assigned



11950
11951
11952
# File 'lib/syntax_tree.rb', line 11950

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



11953
11954
11955
# File 'lib/syntax_tree.rb', line 11953

def location
  @location
end

Instance Method Details

#child_nodesObject



11964
11965
11966
# File 'lib/syntax_tree.rb', line 11964

def child_nodes
  [constant]
end

#format(q) ⇒ Object



11968
11969
11970
11971
# File 'lib/syntax_tree.rb', line 11968

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

#pretty_print(q) ⇒ Object



11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
# File 'lib/syntax_tree.rb', line 11973

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



11984
11985
11986
11987
11988
11989
11990
11991
# File 'lib/syntax_tree.rb', line 11984

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