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.



4286
4287
4288
4289
4290
# File 'lib/syntax_tree.rb', line 4286

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



4284
4285
4286
# File 'lib/syntax_tree.rb', line 4284

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



4281
4282
4283
# File 'lib/syntax_tree.rb', line 4281

def location
  @location
end

#valueObject (readonly)

String

the name of the class variable



4278
4279
4280
# File 'lib/syntax_tree.rb', line 4278

def value
  @value
end

Instance Method Details

#child_nodesObject



4292
4293
4294
# File 'lib/syntax_tree.rb', line 4292

def child_nodes
  []
end

#format(q) ⇒ Object



4296
4297
4298
# File 'lib/syntax_tree.rb', line 4296

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

#pretty_print(q) ⇒ Object



4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
# File 'lib/syntax_tree.rb', line 4300

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



4311
4312
4313
4314
4315
# File 'lib/syntax_tree.rb', line 4311

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