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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of VarAlias.



8613
8614
8615
8616
8617
8618
# File 'lib/syntax_tree/node.rb', line 8613

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



8611
8612
8613
# File 'lib/syntax_tree/node.rb', line 8611

def comments
  @comments
end

#leftObject (readonly)

GVar

the new alias of the variable



8605
8606
8607
# File 'lib/syntax_tree/node.rb', line 8605

def left
  @left
end

#rightObject (readonly)

Backref | GVar

the current name of the variable to be aliased



8608
8609
8610
# File 'lib/syntax_tree/node.rb', line 8608

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



8620
8621
8622
# File 'lib/syntax_tree/node.rb', line 8620

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

#child_nodesObject Also known as: deconstruct



8624
8625
8626
# File 'lib/syntax_tree/node.rb', line 8624

def child_nodes
  [left, right]
end

#deconstruct_keys(keys) ⇒ Object



8630
8631
8632
# File 'lib/syntax_tree/node.rb', line 8630

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

#format(q) ⇒ Object



8634
8635
8636
8637
8638
8639
8640
8641
# File 'lib/syntax_tree/node.rb', line 8634

def format(q)
  keyword = "alias "

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