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.



5904
5905
5906
5907
5908
# File 'lib/syntax_tree.rb', line 5904

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



5902
5903
5904
# File 'lib/syntax_tree.rb', line 5902

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



5899
5900
5901
# File 'lib/syntax_tree.rb', line 5899

def location
  @location
end

#valueObject (readonly)

String

the name of the global variable



5896
5897
5898
# File 'lib/syntax_tree.rb', line 5896

def value
  @value
end

Instance Method Details

#child_nodesObject



5910
5911
5912
# File 'lib/syntax_tree.rb', line 5910

def child_nodes
  []
end

#format(q) ⇒ Object



5914
5915
5916
# File 'lib/syntax_tree.rb', line 5914

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

#pretty_print(q) ⇒ Object



5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
# File 'lib/syntax_tree.rb', line 5918

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



5929
5930
5931
5932
5933
# File 'lib/syntax_tree.rb', line 5929

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