Class: SyntaxTree::ConstRef

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

Overview

ConstRef represents the name of the constant being used in a class or module declaration.

class Container
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstRef.



4356
4357
4358
4359
4360
# File 'lib/syntax_tree.rb', line 4356

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



4354
4355
4356
# File 'lib/syntax_tree.rb', line 4354

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



4348
4349
4350
# File 'lib/syntax_tree.rb', line 4348

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



4351
4352
4353
# File 'lib/syntax_tree.rb', line 4351

def location
  @location
end

Instance Method Details

#child_nodesObject



4362
4363
4364
# File 'lib/syntax_tree.rb', line 4362

def child_nodes
  [constant]
end

#format(q) ⇒ Object



4366
4367
4368
# File 'lib/syntax_tree.rb', line 4366

def format(q)
  q.format(constant)
end

#pretty_print(q) ⇒ Object



4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
# File 'lib/syntax_tree.rb', line 4370

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

    q.breakable
    q.pp(constant)

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

#to_json(*opts) ⇒ Object



4381
4382
4383
4384
4385
4386
4387
4388
# File 'lib/syntax_tree.rb', line 4381

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