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.



4249
4250
4251
4252
4253
# File 'lib/syntax_tree.rb', line 4249

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



4247
4248
4249
# File 'lib/syntax_tree.rb', line 4247

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



4244
4245
4246
# File 'lib/syntax_tree.rb', line 4244

def location
  @location
end

#valueObject (readonly)

String

the name of the class variable



4241
4242
4243
# File 'lib/syntax_tree.rb', line 4241

def value
  @value
end

Instance Method Details

#child_nodesObject



4255
4256
4257
# File 'lib/syntax_tree.rb', line 4255

def child_nodes
  []
end

#format(q) ⇒ Object



4259
4260
4261
# File 'lib/syntax_tree.rb', line 4259

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

#pretty_print(q) ⇒ Object



4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
# File 'lib/syntax_tree.rb', line 4263

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



4274
4275
4276
4277
4278
# File 'lib/syntax_tree.rb', line 4274

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