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

#pretty_print, #to_json

Constructor Details

#initialize(value:, location:, comments: []) ⇒ Const

Returns a new instance of Const.



3129
3130
3131
3132
3133
# File 'lib/syntax_tree/node.rb', line 3129

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



3127
3128
3129
# File 'lib/syntax_tree/node.rb', line 3127

def comments
  @comments
end

#valueObject (readonly)

String

the name of the constant



3124
3125
3126
# File 'lib/syntax_tree/node.rb', line 3124

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



3135
3136
3137
# File 'lib/syntax_tree/node.rb', line 3135

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

#child_nodesObject Also known as: deconstruct



3139
3140
3141
# File 'lib/syntax_tree/node.rb', line 3139

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



3145
3146
3147
# File 'lib/syntax_tree/node.rb', line 3145

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

#format(q) ⇒ Object



3149
3150
3151
# File 'lib/syntax_tree/node.rb', line 3149

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