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.



3169
3170
3171
3172
3173
3174
# File 'lib/syntax_tree/node.rb', line 3169

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



3167
3168
3169
# File 'lib/syntax_tree/node.rb', line 3167

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3164
3165
3166
# File 'lib/syntax_tree/node.rb', line 3164

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



3161
3162
3163
# File 'lib/syntax_tree/node.rb', line 3161

def parent
  @parent
end

Instance Method Details

#accept(visitor) ⇒ Object



3176
3177
3178
# File 'lib/syntax_tree/node.rb', line 3176

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

#child_nodesObject Also known as: deconstruct



3180
3181
3182
# File 'lib/syntax_tree/node.rb', line 3180

def child_nodes
  [parent, constant]
end

#deconstruct_keys(keys) ⇒ Object



3186
3187
3188
3189
3190
3191
3192
3193
# File 'lib/syntax_tree/node.rb', line 3186

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

#format(q) ⇒ Object



3195
3196
3197
3198
3199
# File 'lib/syntax_tree/node.rb', line 3195

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