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.



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

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



9406
9407
9408
# File 'lib/syntax_tree/node.rb', line 9406

def comments
  @comments
end

#leftObject (readonly)

GVar

the new alias of the variable



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

def left
  @left
end

#rightObject (readonly)

Backref | GVar

the current name of the variable to be aliased



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

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



9419
9420
9421
# File 'lib/syntax_tree/node.rb', line 9419

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



9425
9426
9427
# File 'lib/syntax_tree/node.rb', line 9425

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

#format(q) ⇒ Object



9429
9430
9431
9432
9433
9434
9435
9436
# File 'lib/syntax_tree/node.rb', line 9429

def format(q)
  keyword = "alias "

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