Class: SyntaxTree::Const

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

Overview

Const represents a literal value that looks like a constant. This could actually be a reference to a constant:

Constant

It could also be something that looks like a constant in another context, as in a method call to a capitalized method:

object.Constant

or a symbol that starts with a capital letter:

:Constant

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(value:, location:, comments: []) ⇒ Const

Returns a new instance of Const.



3233
3234
3235
3236
3237
# File 'lib/syntax_tree/node.rb', line 3233

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3231
3232
3233
# File 'lib/syntax_tree/node.rb', line 3231

def comments
  @comments
end

#valueObject (readonly)

String

the name of the constant



3228
3229
3230
# File 'lib/syntax_tree/node.rb', line 3228

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



3239
3240
3241
# File 'lib/syntax_tree/node.rb', line 3239

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



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

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

#format(q) ⇒ Object



3253
3254
3255
# File 'lib/syntax_tree/node.rb', line 3253

def format(q)
  q.text(value)
end