Class: SyntaxTree::VarRef

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

VarRef represents a variable reference.

true

This can be a plain local variable like the example above. It can also be a constant, a class variable, a global variable, an instance variable, a keyword (like self, nil, true, or false), or a numbered block variable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of VarRef.



12872
12873
12874
12875
12876
# File 'lib/syntax_tree.rb', line 12872

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



12870
12871
12872
# File 'lib/syntax_tree.rb', line 12870

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12867
12868
12869
# File 'lib/syntax_tree.rb', line 12867

def location
  @location
end

#valueObject (readonly)

Const | CVar | GVar | Ident | IVar | Kw

the value of this node



12864
12865
12866
# File 'lib/syntax_tree.rb', line 12864

def value
  @value
end

Instance Method Details

#child_nodesObject



12878
12879
12880
# File 'lib/syntax_tree.rb', line 12878

def child_nodes
  [value]
end

#format(q) ⇒ Object



12882
12883
12884
# File 'lib/syntax_tree.rb', line 12882

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

#pretty_print(q) ⇒ Object



12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
# File 'lib/syntax_tree.rb', line 12886

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("var_ref")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



12897
12898
12899
12900
12901
# File 'lib/syntax_tree.rb', line 12897

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