Class: SyntaxTree::TopConstField

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

Overview

TopConstField is always the child node of some kind of assignment. It represents when you’re assigning to a constant that is being referenced at the top level.

::Constant = 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(constant:, location:, comments: []) ⇒ TopConstField

Returns a new instance of TopConstField.



8639
8640
8641
8642
8643
# File 'lib/syntax_tree/node.rb', line 8639

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



8637
8638
8639
# File 'lib/syntax_tree/node.rb', line 8637

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being assigned



8634
8635
8636
# File 'lib/syntax_tree/node.rb', line 8634

def constant
  @constant
end

Instance Method Details

#accept(visitor) ⇒ Object



8645
8646
8647
# File 'lib/syntax_tree/node.rb', line 8645

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

#child_nodesObject Also known as: deconstruct



8649
8650
8651
# File 'lib/syntax_tree/node.rb', line 8649

def child_nodes
  [constant]
end

#deconstruct_keys(_keys) ⇒ Object



8655
8656
8657
# File 'lib/syntax_tree/node.rb', line 8655

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

#format(q) ⇒ Object



8659
8660
8661
8662
# File 'lib/syntax_tree/node.rb', line 8659

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