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.



3794
3795
3796
3797
3798
3799
# File 'lib/syntax_tree/node.rb', line 3794

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



3792
3793
3794
# File 'lib/syntax_tree/node.rb', line 3792

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3789
3790
3791
# File 'lib/syntax_tree/node.rb', line 3789

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



3786
3787
3788
# File 'lib/syntax_tree/node.rb', line 3786

def parent
  @parent
end

Instance Method Details

#===(other) ⇒ Object



3838
3839
3840
3841
# File 'lib/syntax_tree/node.rb', line 3838

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

#accept(visitor) ⇒ Object



3801
3802
3803
# File 'lib/syntax_tree/node.rb', line 3801

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

#child_nodesObject Also known as: deconstruct



3805
3806
3807
# File 'lib/syntax_tree/node.rb', line 3805

def child_nodes
  [parent, constant]
end

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



3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
# File 'lib/syntax_tree/node.rb', line 3809

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



3823
3824
3825
3826
3827
3828
3829
3830
# File 'lib/syntax_tree/node.rb', line 3823

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

#format(q) ⇒ Object



3832
3833
3834
3835
3836
# File 'lib/syntax_tree/node.rb', line 3832

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