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.



11251
11252
11253
11254
11255
# File 'lib/syntax_tree.rb', line 11251

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



11249
11250
11251
# File 'lib/syntax_tree.rb', line 11249

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being assigned



11243
11244
11245
# File 'lib/syntax_tree.rb', line 11243

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



11246
11247
11248
# File 'lib/syntax_tree.rb', line 11246

def location
  @location
end

Instance Method Details

#child_nodesObject



11257
11258
11259
# File 'lib/syntax_tree.rb', line 11257

def child_nodes
  [constant]
end

#pretty_print(q) ⇒ Object



11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
# File 'lib/syntax_tree.rb', line 11261

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



11272
11273
11274
11275
11276
11277
11278
11279
# File 'lib/syntax_tree.rb', line 11272

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