Class: SyntaxTree::ConstPathField

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

Overview

ConstPathField represents the child node of some kind of assignment. It represents when you’re assigning to a constant that is being referenced as a child of another variable.

object::Const = value

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstPathField.



3468
3469
3470
3471
3472
3473
# File 'lib/syntax_tree/node.rb', line 3468

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



3466
3467
3468
# File 'lib/syntax_tree/node.rb', line 3466

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3463
3464
3465
# File 'lib/syntax_tree/node.rb', line 3463

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



3460
3461
3462
# File 'lib/syntax_tree/node.rb', line 3460

def parent
  @parent
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



3475
3476
3477
# File 'lib/syntax_tree/node.rb', line 3475

def child_nodes
  [parent, constant]
end

#deconstruct_keys(keys) ⇒ Object



3481
3482
3483
3484
3485
3486
3487
3488
# File 'lib/syntax_tree/node.rb', line 3481

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

#format(q) ⇒ Object



3490
3491
3492
3493
3494
# File 'lib/syntax_tree/node.rb', line 3490

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

#pretty_print(q) ⇒ Object



3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
# File 'lib/syntax_tree/node.rb', line 3496

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

    q.breakable
    q.pp(parent)

    q.breakable
    q.pp(constant)

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

#to_json(*opts) ⇒ Object



3510
3511
3512
3513
3514
3515
3516
3517
3518
# File 'lib/syntax_tree/node.rb', line 3510

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