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.



9173
9174
9175
9176
9177
9178
# File 'lib/syntax_tree/node.rb', line 9173

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



9171
9172
9173
# File 'lib/syntax_tree/node.rb', line 9171

def comments
  @comments
end

#leftObject (readonly)

GVar

the new alias of the variable



9165
9166
9167
# File 'lib/syntax_tree/node.rb', line 9165

def left
  @left
end

#rightObject (readonly)

Backref | GVar

the current name of the variable to be aliased



9168
9169
9170
# File 'lib/syntax_tree/node.rb', line 9168

def right
  @right
end

Instance Method Details

#accept(visitor) ⇒ Object



9180
9181
9182
# File 'lib/syntax_tree/node.rb', line 9180

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

#child_nodesObject Also known as: deconstruct



9184
9185
9186
# File 'lib/syntax_tree/node.rb', line 9184

def child_nodes
  [left, right]
end

#deconstruct_keys(keys) ⇒ Object



9190
9191
9192
# File 'lib/syntax_tree/node.rb', line 9190

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

#format(q) ⇒ Object



9194
9195
9196
9197
9198
9199
9200
9201
# File 'lib/syntax_tree/node.rb', line 9194

def format(q)
  keyword = "alias "

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