Class: SyntaxTree::ConstPathRef

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

Overview

ConstPathRef represents referencing a constant by a path.

object::Const

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

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



3414
3415
3416
3417
3418
3419
# File 'lib/syntax_tree/node.rb', line 3414

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



3412
3413
3414
# File 'lib/syntax_tree/node.rb', line 3412

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3409
3410
3411
# File 'lib/syntax_tree/node.rb', line 3409

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



3406
3407
3408
# File 'lib/syntax_tree/node.rb', line 3406

def parent
  @parent
end

Instance Method Details

#accept(visitor) ⇒ Object



3421
3422
3423
# File 'lib/syntax_tree/node.rb', line 3421

def accept(visitor)
  visitor.visit_const_path_ref(self)
end

#child_nodesObject Also known as: deconstruct



3425
3426
3427
# File 'lib/syntax_tree/node.rb', line 3425

def child_nodes
  [parent, constant]
end

#deconstruct_keys(_keys) ⇒ Object



3431
3432
3433
3434
3435
3436
3437
3438
# File 'lib/syntax_tree/node.rb', line 3431

def deconstruct_keys(_keys)
  {
    parent: parent,
    constant: constant,
    location: location,
    comments: comments
  }
end

#format(q) ⇒ Object



3440
3441
3442
3443
3444
# File 'lib/syntax_tree/node.rb', line 3440

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