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

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CVar.



3653
3654
3655
3656
3657
# File 'lib/syntax_tree/node.rb', line 3653

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



3651
3652
3653
# File 'lib/syntax_tree/node.rb', line 3651

def comments
  @comments
end

#valueObject (readonly)

String

the name of the class variable



3648
3649
3650
# File 'lib/syntax_tree/node.rb', line 3648

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



3659
3660
3661
# File 'lib/syntax_tree/node.rb', line 3659

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



3665
3666
3667
# File 'lib/syntax_tree/node.rb', line 3665

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

#format(q) ⇒ Object



3669
3670
3671
# File 'lib/syntax_tree/node.rb', line 3669

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

#pretty_print(q) ⇒ Object



3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
# File 'lib/syntax_tree/node.rb', line 3673

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



3684
3685
3686
3687
3688
# File 'lib/syntax_tree/node.rb', line 3684

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