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.



9447
9448
9449
9450
9451
9452
# File 'lib/syntax_tree/node.rb', line 9447

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9445
9446
9447
# File 'lib/syntax_tree/node.rb', line 9445

def comments
  @comments
end

#leftObject (readonly)

GVar

the new alias of the variable



9439
9440
9441
# File 'lib/syntax_tree/node.rb', line 9439

def left
  @left
end

#rightObject (readonly)

Backref | GVar

the current name of the variable to be aliased



9442
9443
9444
# File 'lib/syntax_tree/node.rb', line 9442

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



9454
9455
9456
# File 'lib/syntax_tree/node.rb', line 9454

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

#child_nodesObject Also known as: deconstruct



9458
9459
9460
# File 'lib/syntax_tree/node.rb', line 9458

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



9464
9465
9466
# File 'lib/syntax_tree/node.rb', line 9464

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

#format(q) ⇒ Object



9468
9469
9470
9471
9472
9473
9474
9475
# File 'lib/syntax_tree/node.rb', line 9468

def format(q)
  keyword = "alias "

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