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.



12256
12257
12258
12259
12260
# File 'lib/syntax_tree.rb', line 12256

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



12254
12255
12256
# File 'lib/syntax_tree.rb', line 12254

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12251
12252
12253
# File 'lib/syntax_tree.rb', line 12251

def location
  @location
end

#valueObject (readonly)

Const | CVar | GVar | Ident | IVar | Kw

the value of this node



12248
12249
12250
# File 'lib/syntax_tree.rb', line 12248

def value
  @value
end

Instance Method Details

#child_nodesObject



12262
12263
12264
# File 'lib/syntax_tree.rb', line 12262

def child_nodes
  [value]
end

#format(q) ⇒ Object



12266
12267
12268
# File 'lib/syntax_tree.rb', line 12266

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

#pretty_print(q) ⇒ Object



12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
# File 'lib/syntax_tree.rb', line 12270

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



12281
12282
12283
12284
12285
# File 'lib/syntax_tree.rb', line 12281

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