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.



4411
4412
4413
4414
4415
# File 'lib/syntax_tree.rb', line 4411

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



4409
4410
4411
# File 'lib/syntax_tree.rb', line 4409

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



4406
4407
4408
# File 'lib/syntax_tree.rb', line 4406

def location
  @location
end

#valueObject (readonly)

String

the name of the class variable



4403
4404
4405
# File 'lib/syntax_tree.rb', line 4403

def value
  @value
end

Instance Method Details

#child_nodesObject



4417
4418
4419
# File 'lib/syntax_tree.rb', line 4417

def child_nodes
  []
end

#format(q) ⇒ Object



4421
4422
4423
# File 'lib/syntax_tree.rb', line 4421

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

#pretty_print(q) ⇒ Object



4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
# File 'lib/syntax_tree.rb', line 4425

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



4436
4437
4438
4439
4440
# File 'lib/syntax_tree.rb', line 4436

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