Class: SyntaxTree::GVar

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

Overview

GVar represents a global variable literal.

$variable

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: []) ⇒ GVar

Returns a new instance of GVar.



4233
4234
4235
4236
4237
# File 'lib/syntax_tree/node.rb', line 4233

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



4231
4232
4233
# File 'lib/syntax_tree/node.rb', line 4231

def comments
  @comments
end

#valueObject (readonly)

String

the name of the global variable



4228
4229
4230
# File 'lib/syntax_tree/node.rb', line 4228

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



4239
4240
4241
# File 'lib/syntax_tree/node.rb', line 4239

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

#child_nodesObject Also known as: deconstruct



4243
4244
4245
# File 'lib/syntax_tree/node.rb', line 4243

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



4249
4250
4251
# File 'lib/syntax_tree/node.rb', line 4249

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

#format(q) ⇒ Object



4253
4254
4255
# File 'lib/syntax_tree/node.rb', line 4253

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