class SyntaxTree::AliasNode
Alias represents the use of the alias
keyword with regular arguments (not global variables). The alias
keyword is used to make a method respond to another name as well as the current one.
alias aliased_name name
For
the example above, in the current context you can now call aliased_name and it will execute the name method. When
you’re aliasing two methods, you can either provide bare words (like the example above) or you can provide symbols (note that this includes dynamic symbols like :“left-#{middle}-right”).
Attributes
left[R]
DynaSymbol
|GVar
|SymbolLiteral
-
the new name of the method
right[R]
Backref
|DynaSymbol
|GVar
|SymbolLiteral
-
the old name of the method
Public Class Methods
new(left:, right:, location:)
click to toggle source
# File lib/syntax_tree/node.rb, line 496 def initialize(left:, right:, location:) @left = left @right = right @location = location @comments = [] end
Public Instance Methods
===(other)
click to toggle source
# File lib/syntax_tree/node.rb, line 545 def ===(other) other.is_a?(AliasNode) && left === other.left && right === other.right end
accept(visitor)
click to toggle source
# File lib/syntax_tree/node.rb, line 503 def accept(visitor) visitor.visit_alias(self) end
child_nodes()
click to toggle source
# File lib/syntax_tree/node.rb, line 507 def child_nodes [left, right] end
Also aliased as: deconstruct
copy(left: nil, right: nil, location: nil)
click to toggle source
# File lib/syntax_tree/node.rb, line 511 def copy(left: nil, right: nil, location: nil) node = AliasNode.new( left: left || self.left, right: right || self.right, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
deconstruct_keys(_keys)
click to toggle source
# File lib/syntax_tree/node.rb, line 525 def deconstruct_keys(_keys) { left: left, right: right, location: location, comments: comments } end
format(q)
click to toggle source
# File lib/syntax_tree/node.rb, line 529 def format(q) keyword = "alias " left_argument = AliasArgumentFormatter.new(left) q.group do q.text(keyword) q.format(left_argument, stackable: false) q.group do q.nest(keyword.length) do left_argument.comments.any? ? q.breakable_force : q.breakable_space q.format(AliasArgumentFormatter.new(right), stackable: false) end end end end
var_alias?()
click to toggle source
# File lib/syntax_tree/node.rb, line 549 def var_alias? left.is_a?(GVar) end