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



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

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



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

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3823
3824
3825
# File 'lib/syntax_tree/node.rb', line 3823

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



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

def parent
  @parent
end

Instance Method Details

#===(other) ⇒ Object



3872
3873
3874
3875
# File 'lib/syntax_tree/node.rb', line 3872

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

#accept(visitor) ⇒ Object



3835
3836
3837
# File 'lib/syntax_tree/node.rb', line 3835

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [parent, constant]
end

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



3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
# File 'lib/syntax_tree/node.rb', line 3843

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



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

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

#format(q) ⇒ Object



3866
3867
3868
3869
3870
# File 'lib/syntax_tree/node.rb', line 3866

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