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.



12791
12792
12793
12794
12795
# File 'lib/syntax_tree.rb', line 12791

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



12789
12790
12791
# File 'lib/syntax_tree.rb', line 12789

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12786
12787
12788
# File 'lib/syntax_tree.rb', line 12786

def location
  @location
end

#valueObject (readonly)

Const | CVar | GVar | Ident | IVar | Kw

the value of this node



12783
12784
12785
# File 'lib/syntax_tree.rb', line 12783

def value
  @value
end

Instance Method Details

#child_nodesObject



12797
12798
12799
# File 'lib/syntax_tree.rb', line 12797

def child_nodes
  [value]
end

#format(q) ⇒ Object



12801
12802
12803
# File 'lib/syntax_tree.rb', line 12801

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

#pretty_print(q) ⇒ Object



12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
# File 'lib/syntax_tree.rb', line 12805

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



12816
12817
12818
12819
12820
# File 'lib/syntax_tree.rb', line 12816

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