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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of ConstRef.



3460
3461
3462
3463
3464
# File 'lib/syntax_tree/node.rb', line 3460

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



3458
3459
3460
# File 'lib/syntax_tree/node.rb', line 3458

def comments
  @comments
end

#constantObject (readonly)

Const

the constant itself



3455
3456
3457
# File 'lib/syntax_tree/node.rb', line 3455

def constant
  @constant
end

Instance Method Details

#accept(visitor) ⇒ Object



3466
3467
3468
# File 'lib/syntax_tree/node.rb', line 3466

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

#child_nodesObject Also known as: deconstruct



3470
3471
3472
# File 'lib/syntax_tree/node.rb', line 3470

def child_nodes
  [constant]
end

#deconstruct_keys(_keys) ⇒ Object



3476
3477
3478
# File 'lib/syntax_tree/node.rb', line 3476

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

#format(q) ⇒ Object



3480
3481
3482
# File 'lib/syntax_tree/node.rb', line 3480

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