Class: SyntaxTree::CVar

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

Overview

CVar represents the use of a class variable.

@@variable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CVar.



3987
3988
3989
3990
3991
# File 'lib/syntax_tree.rb', line 3987

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



3985
3986
3987
# File 'lib/syntax_tree.rb', line 3985

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



3982
3983
3984
# File 'lib/syntax_tree.rb', line 3982

def location
  @location
end

#valueObject (readonly)

String

the name of the class variable



3979
3980
3981
# File 'lib/syntax_tree.rb', line 3979

def value
  @value
end

Instance Method Details

#child_nodesObject



3993
3994
3995
# File 'lib/syntax_tree.rb', line 3993

def child_nodes
  []
end

#format(q) ⇒ Object



3997
3998
3999
# File 'lib/syntax_tree.rb', line 3997

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

#pretty_print(q) ⇒ Object



4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
# File 'lib/syntax_tree.rb', line 4001

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



4012
4013
4014
4015
4016
# File 'lib/syntax_tree.rb', line 4012

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