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



9034
9035
9036
9037
9038
# File 'lib/syntax_tree/node.rb', line 9034

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



9032
9033
9034
# File 'lib/syntax_tree/node.rb', line 9032

def comments
  @comments
end

#constantObject (readonly)

Const

the constant being assigned



9029
9030
9031
# File 'lib/syntax_tree/node.rb', line 9029

def constant
  @constant
end

Instance Method Details

#accept(visitor) ⇒ Object



9040
9041
9042
# File 'lib/syntax_tree/node.rb', line 9040

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

#child_nodesObject Also known as: deconstruct



9044
9045
9046
# File 'lib/syntax_tree/node.rb', line 9044

def child_nodes
  [constant]
end

#deconstruct_keys(_keys) ⇒ Object



9050
9051
9052
# File 'lib/syntax_tree/node.rb', line 9050

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

#format(q) ⇒ Object



9054
9055
9056
9057
# File 'lib/syntax_tree/node.rb', line 9054

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