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



6225
6226
6227
6228
6229
# File 'lib/syntax_tree.rb', line 6225

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



6223
6224
6225
# File 'lib/syntax_tree.rb', line 6223

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



6220
6221
6222
# File 'lib/syntax_tree.rb', line 6220

def location
  @location
end

#valueObject (readonly)

String

the name of the global variable



6217
6218
6219
# File 'lib/syntax_tree.rb', line 6217

def value
  @value
end

Instance Method Details

#child_nodesObject



6231
6232
6233
# File 'lib/syntax_tree.rb', line 6231

def child_nodes
  []
end

#format(q) ⇒ Object



6235
6236
6237
# File 'lib/syntax_tree.rb', line 6235

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

#pretty_print(q) ⇒ Object



6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
# File 'lib/syntax_tree.rb', line 6239

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



6250
6251
6252
6253
6254
# File 'lib/syntax_tree.rb', line 6250

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