Class: SyntaxTree::ConstPathRef

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

ConstPathRef represents referencing a constant by a path.

object::Const

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: []) ⇒ ConstPathRef

Returns a new instance of ConstPathRef.



3249
3250
3251
3252
3253
3254
# File 'lib/syntax_tree/node.rb', line 3249

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



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

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



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

def constant
  @constant
end

#parentObject (readonly)

untyped

the source of the constant



3241
3242
3243
# File 'lib/syntax_tree/node.rb', line 3241

def parent
  @parent
end

Instance Method Details

#accept(visitor) ⇒ Object



3256
3257
3258
# File 'lib/syntax_tree/node.rb', line 3256

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

#child_nodesObject Also known as: deconstruct



3260
3261
3262
# File 'lib/syntax_tree/node.rb', line 3260

def child_nodes
  [parent, constant]
end

#deconstruct_keys(_keys) ⇒ Object



3266
3267
3268
3269
3270
3271
3272
3273
# File 'lib/syntax_tree/node.rb', line 3266

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

#format(q) ⇒ Object



3275
3276
3277
3278
3279
# File 'lib/syntax_tree/node.rb', line 3275

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