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



3367
3368
3369
3370
3371
3372
# File 'lib/syntax_tree/node.rb', line 3367

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



3365
3366
3367
# File 'lib/syntax_tree/node.rb', line 3365

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3362
3363
3364
# File 'lib/syntax_tree/node.rb', line 3362

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



3359
3360
3361
# File 'lib/syntax_tree/node.rb', line 3359

def parent
  @parent
end

Instance Method Details

#accept(visitor) ⇒ Object



3374
3375
3376
# File 'lib/syntax_tree/node.rb', line 3374

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

#child_nodesObject Also known as: deconstruct



3378
3379
3380
# File 'lib/syntax_tree/node.rb', line 3378

def child_nodes
  [parent, constant]
end

#deconstruct_keys(_keys) ⇒ Object



3384
3385
3386
3387
3388
3389
3390
3391
# File 'lib/syntax_tree/node.rb', line 3384

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

#format(q) ⇒ Object



3393
3394
3395
3396
3397
# File 'lib/syntax_tree/node.rb', line 3393

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