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

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of ConstPathField.



2821
2822
2823
2824
2825
2826
# File 'lib/syntax_tree/node.rb', line 2821

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



2819
2820
2821
# File 'lib/syntax_tree/node.rb', line 2819

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



2816
2817
2818
# File 'lib/syntax_tree/node.rb', line 2816

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



2813
2814
2815
# File 'lib/syntax_tree/node.rb', line 2813

def parent
  @parent
end

Instance Method Details

#accept(visitor) ⇒ Object



2828
2829
2830
# File 'lib/syntax_tree/node.rb', line 2828

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

#child_nodesObject Also known as: deconstruct



2832
2833
2834
# File 'lib/syntax_tree/node.rb', line 2832

def child_nodes
  [parent, constant]
end

#deconstruct_keys(keys) ⇒ Object



2838
2839
2840
2841
2842
2843
2844
2845
# File 'lib/syntax_tree/node.rb', line 2838

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

#format(q) ⇒ Object



2847
2848
2849
2850
2851
# File 'lib/syntax_tree/node.rb', line 2847

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