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:, comments: []) ⇒ ConstPathField

Returns a new instance of ConstPathField.



3236
3237
3238
3239
3240
3241
# File 'lib/syntax_tree/node.rb', line 3236

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



3234
3235
3236
# File 'lib/syntax_tree/node.rb', line 3234

def comments
  @comments
end

#constant ⇒ Object (readonly)

[Const] the constant itself



3231
3232
3233
# File 'lib/syntax_tree/node.rb', line 3231

def constant
  @constant
end

#parent ⇒ Object (readonly)

[untyped] the source of the constant



3228
3229
3230
# File 'lib/syntax_tree/node.rb', line 3228

def parent
  @parent
end

Instance Method Details

#accept(visitor) ⇒ Object



3243
3244
3245
# File 'lib/syntax_tree/node.rb', line 3243

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

#child_nodes ⇒ Object Also known as: deconstruct



3247
3248
3249
# File 'lib/syntax_tree/node.rb', line 3247

def child_nodes
  [parent, constant]
end

#deconstruct_keys(_keys) ⇒ Object



3253
3254
3255
3256
3257
3258
3259
3260
# File 'lib/syntax_tree/node.rb', line 3253

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

#format(q) ⇒ Object



3262
3263
3264
3265
3266
# File 'lib/syntax_tree/node.rb', line 3262

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