Class: SyntaxTree::ConstRef

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

Overview

ConstRef represents the name of the constant being used in a class or module declaration.

class Container
end

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(constant:, location:, comments: []) ⇒ ConstRef

Returns a new instance of ConstRef.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



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

def constant
  @constant
end

Instance Method Details

#accept(visitor) ⇒ Object



3268
3269
3270
# File 'lib/syntax_tree/node.rb', line 3268

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

#child_nodesObject Also known as: deconstruct



3272
3273
3274
# File 'lib/syntax_tree/node.rb', line 3272

def child_nodes
  [constant]
end

#deconstruct_keys(keys) ⇒ Object



3278
3279
3280
# File 'lib/syntax_tree/node.rb', line 3278

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

#format(q) ⇒ Object



3282
3283
3284
# File 'lib/syntax_tree/node.rb', line 3282

def format(q)
  q.format(constant)
end