Class: SyntaxTree::VarAlias

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

Overview

VarAlias represents when you're using the alias keyword with global variable arguments.

alias $new $old

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(left:, right:, location:, comments: []) ⇒ VarAlias

Returns a new instance of VarAlias.



9397
9398
9399
9400
9401
9402
# File 'lib/syntax_tree/node.rb', line 9397

def initialize(left:, right:, location:, comments: [])
  @left = left
  @right = right
  @location = location
  @comments = comments
end

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



9395
9396
9397
# File 'lib/syntax_tree/node.rb', line 9395

def comments
  @comments
end

#left ⇒ Object (readonly)

[GVar] the new alias of the variable



9389
9390
9391
# File 'lib/syntax_tree/node.rb', line 9389

def left
  @left
end

#right ⇒ Object (readonly)

[Backref | GVar] the current name of the variable to be aliased



9392
9393
9394
# File 'lib/syntax_tree/node.rb', line 9392

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



9404
9405
9406
# File 'lib/syntax_tree/node.rb', line 9404

def accept(visitor)
  visitor.visit_var_alias(self)
end

#child_nodes ⇒ Object Also known as: deconstruct



9408
9409
9410
# File 'lib/syntax_tree/node.rb', line 9408

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



9414
9415
9416
# File 'lib/syntax_tree/node.rb', line 9414

def deconstruct_keys(_keys)
  { left: left, right: right, location: location, comments: comments }
end

#format(q) ⇒ Object



9418
9419
9420
9421
9422
9423
9424
9425
# File 'lib/syntax_tree/node.rb', line 9418

def format(q)
  keyword = "alias "

  q.text(keyword)
  q.format(left)
  q.text(" ")
  q.format(right)
end