Class: SyntaxTree::ConstPathRef

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

Overview

ConstPathRef represents referencing a constant by a path.

object::Const

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstPathRef.



4288
4289
4290
4291
4292
4293
# File 'lib/syntax_tree.rb', line 4288

def initialize(parent:, constant:, location:, comments: [])
  @parent = parent
  @constant = constant
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



4286
4287
4288
# File 'lib/syntax_tree.rb', line 4286

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



4280
4281
4282
# File 'lib/syntax_tree.rb', line 4280

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



4283
4284
4285
# File 'lib/syntax_tree.rb', line 4283

def location
  @location
end

#parentObject (readonly)

untyped

the source of the constant



4277
4278
4279
# File 'lib/syntax_tree.rb', line 4277

def parent
  @parent
end

Instance Method Details

#child_nodesObject



4295
4296
4297
# File 'lib/syntax_tree.rb', line 4295

def child_nodes
  [parent, constant]
end

#format(q) ⇒ Object



4299
4300
4301
4302
4303
# File 'lib/syntax_tree.rb', line 4299

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

#pretty_print(q) ⇒ Object



4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
# File 'lib/syntax_tree.rb', line 4305

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

    q.breakable
    q.pp(parent)

    q.breakable
    q.pp(constant)

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

#to_json(*opts) ⇒ Object



4319
4320
4321
4322
4323
4324
4325
4326
4327
# File 'lib/syntax_tree.rb', line 4319

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