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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ConstPathField.



3579
3580
3581
3582
3583
3584
# File 'lib/syntax_tree/node.rb', line 3579

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



3577
3578
3579
# File 'lib/syntax_tree/node.rb', line 3577

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3571
3572
3573
# File 'lib/syntax_tree/node.rb', line 3571

def constant
  @constant
end

#locationObject (readonly)

Location

the location of this node



3574
3575
3576
# File 'lib/syntax_tree/node.rb', line 3574

def location
  @location
end

#parentObject (readonly)

untyped

the source of the constant



3568
3569
3570
# File 'lib/syntax_tree/node.rb', line 3568

def parent
  @parent
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



3586
3587
3588
# File 'lib/syntax_tree/node.rb', line 3586

def child_nodes
  [parent, constant]
end

#deconstruct_keys(keys) ⇒ Object



3592
3593
3594
3595
3596
3597
3598
3599
# File 'lib/syntax_tree/node.rb', line 3592

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

#format(q) ⇒ Object



3601
3602
3603
3604
3605
# File 'lib/syntax_tree/node.rb', line 3601

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

#pretty_print(q) ⇒ Object



3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
# File 'lib/syntax_tree/node.rb', line 3607

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



3621
3622
3623
3624
3625
3626
3627
3628
3629
# File 'lib/syntax_tree/node.rb', line 3621

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