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.



13004
13005
13006
13007
13008
# File 'lib/syntax_tree.rb', line 13004

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



13002
13003
13004
# File 'lib/syntax_tree.rb', line 13002

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12999
13000
13001
# File 'lib/syntax_tree.rb', line 12999

def location
  @location
end

#valueObject (readonly)

Const | CVar | GVar | Ident | IVar | Kw

the value of this node



12996
12997
12998
# File 'lib/syntax_tree.rb', line 12996

def value
  @value
end

Instance Method Details

#child_nodesObject



13010
13011
13012
# File 'lib/syntax_tree.rb', line 13010

def child_nodes
  [value]
end

#format(q) ⇒ Object



13014
13015
13016
# File 'lib/syntax_tree.rb', line 13014

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

#pretty_print(q) ⇒ Object



13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
# File 'lib/syntax_tree.rb', line 13018

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



13029
13030
13031
13032
13033
# File 'lib/syntax_tree.rb', line 13029

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