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

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(parent:, constant:, location:) ⇒ ConstPathField

Returns a new instance of ConstPathField.



3819
3820
3821
3822
3823
3824
# File 'lib/syntax_tree/node.rb', line 3819

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3817
3818
3819
# File 'lib/syntax_tree/node.rb', line 3817

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3814
3815
3816
# File 'lib/syntax_tree/node.rb', line 3814

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



3811
3812
3813
# File 'lib/syntax_tree/node.rb', line 3811

def parent
  @parent
end

Instance Method Details

#===(other) ⇒ Object



3863
3864
3865
3866
# File 'lib/syntax_tree/node.rb', line 3863

def ===(other)
  other.is_a?(ConstPathField) && parent === other.parent &&
    constant === other.constant
end

#accept(visitor) ⇒ Object



3826
3827
3828
# File 'lib/syntax_tree/node.rb', line 3826

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

#child_nodesObject Also known as: deconstruct



3830
3831
3832
# File 'lib/syntax_tree/node.rb', line 3830

def child_nodes
  [parent, constant]
end

#copy(parent: nil, constant: nil, location: nil) ⇒ Object



3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
# File 'lib/syntax_tree/node.rb', line 3834

def copy(parent: nil, constant: nil, location: nil)
  node =
    ConstPathField.new(
      parent: parent || self.parent,
      constant: constant || self.constant,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



3848
3849
3850
3851
3852
3853
3854
3855
# File 'lib/syntax_tree/node.rb', line 3848

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

#format(q) ⇒ Object



3857
3858
3859
3860
3861
# File 'lib/syntax_tree/node.rb', line 3857

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