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

Constructor Details

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

Returns a new instance of GVar.



5283
5284
5285
5286
5287
# File 'lib/syntax_tree/node.rb', line 5283

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



5281
5282
5283
# File 'lib/syntax_tree/node.rb', line 5281

def comments
  @comments
end

#valueObject (readonly)

String

the name of the global variable



5278
5279
5280
# File 'lib/syntax_tree/node.rb', line 5278

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



5289
5290
5291
# File 'lib/syntax_tree/node.rb', line 5289

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



5295
5296
5297
# File 'lib/syntax_tree/node.rb', line 5295

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

#format(q) ⇒ Object



5299
5300
5301
# File 'lib/syntax_tree/node.rb', line 5299

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

#pretty_print(q) ⇒ Object



5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
# File 'lib/syntax_tree/node.rb', line 5303

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("gvar")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



5314
5315
5316
5317
5318
# File 'lib/syntax_tree/node.rb', line 5314

def to_json(*opts)
  { type: :gvar, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end