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



9681
9682
9683
9684
9685
9686
# File 'lib/syntax_tree/node.rb', line 9681

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



9679
9680
9681
# File 'lib/syntax_tree/node.rb', line 9679

def comments
  @comments
end

#leftObject (readonly)

GVar

the new alias of the variable



9673
9674
9675
# File 'lib/syntax_tree/node.rb', line 9673

def left
  @left
end

#rightObject (readonly)

Backref | GVar

the current name of the variable to be aliased



9676
9677
9678
# File 'lib/syntax_tree/node.rb', line 9676

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



9688
9689
9690
# File 'lib/syntax_tree/node.rb', line 9688

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

#child_nodesObject Also known as: deconstruct



9692
9693
9694
# File 'lib/syntax_tree/node.rb', line 9692

def child_nodes
  [left, right]
end

#deconstruct_keys(_keys) ⇒ Object



9698
9699
9700
# File 'lib/syntax_tree/node.rb', line 9698

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

#format(q) ⇒ Object



9702
9703
9704
9705
9706
9707
9708
9709
# File 'lib/syntax_tree/node.rb', line 9702

def format(q)
  keyword = "alias "

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