Class: SyntaxTree::CVar

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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.



3773
3774
3775
3776
3777
# File 'lib/syntax_tree/node.rb', line 3773

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



3771
3772
3773
# File 'lib/syntax_tree/node.rb', line 3771

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



3768
3769
3770
# File 'lib/syntax_tree/node.rb', line 3768

def location
  @location
end

#valueObject (readonly)

String

the name of the class variable



3765
3766
3767
# File 'lib/syntax_tree/node.rb', line 3765

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



3779
3780
3781
# File 'lib/syntax_tree/node.rb', line 3779

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



3785
3786
3787
# File 'lib/syntax_tree/node.rb', line 3785

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



3789
3790
3791
# File 'lib/syntax_tree/node.rb', line 3789

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

#pretty_print(q) ⇒ Object



3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
# File 'lib/syntax_tree/node.rb', line 3793

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



3804
3805
3806
3807
3808
# File 'lib/syntax_tree/node.rb', line 3804

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