Class: SyntaxTree::GVar

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

Overview

GVar represents a global variable literal.

$variable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of GVar.



6394
6395
6396
6397
6398
# File 'lib/syntax_tree.rb', line 6394

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



6392
6393
6394
# File 'lib/syntax_tree.rb', line 6392

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



6389
6390
6391
# File 'lib/syntax_tree.rb', line 6389

def location
  @location
end

#valueObject (readonly)

String

the name of the global variable



6386
6387
6388
# File 'lib/syntax_tree.rb', line 6386

def value
  @value
end

Instance Method Details

#child_nodesObject



6400
6401
6402
# File 'lib/syntax_tree.rb', line 6400

def child_nodes
  []
end

#format(q) ⇒ Object



6404
6405
6406
# File 'lib/syntax_tree.rb', line 6404

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

#pretty_print(q) ⇒ Object



6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
# File 'lib/syntax_tree.rb', line 6408

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



6419
6420
6421
6422
6423
# File 'lib/syntax_tree.rb', line 6419

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