Class: SyntaxTree::Alias
Overview
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”).
Defined Under Namespace
Classes: AliasArgumentFormatter
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#left ⇒ Object
readonly
- DynaSymbol | SymbolLiteral
-
the new name of the method.
-
#right ⇒ Object
readonly
- DynaSymbol | SymbolLiteral
-
the old name of the method.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(left:, right:, location:, comments: []) ⇒ Alias
constructor
A new instance of Alias.
Methods inherited from Node
Constructor Details
#initialize(left:, right:, location:, comments: []) ⇒ Alias
Returns a new instance of Alias.
360 361 362 363 364 365 |
# File 'lib/syntax_tree/node.rb', line 360 def initialize(left:, right:, location:, comments: []) @left = left @right = right @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
358 359 360 |
# File 'lib/syntax_tree/node.rb', line 358 def comments @comments end |
#left ⇒ Object (readonly)
- DynaSymbol | SymbolLiteral
-
the new name of the method
352 353 354 |
# File 'lib/syntax_tree/node.rb', line 352 def left @left end |
#right ⇒ Object (readonly)
- DynaSymbol | SymbolLiteral
-
the old name of the method
355 356 357 |
# File 'lib/syntax_tree/node.rb', line 355 def right @right end |
Instance Method Details
#accept(visitor) ⇒ Object
367 368 369 |
# File 'lib/syntax_tree/node.rb', line 367 def accept(visitor) visitor.visit_alias(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
371 372 373 |
# File 'lib/syntax_tree/node.rb', line 371 def child_nodes [left, right] end |
#deconstruct_keys(keys) ⇒ Object
377 378 379 |
# File 'lib/syntax_tree/node.rb', line 377 def deconstruct_keys(keys) { left: left, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/syntax_tree/node.rb', line 381 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 q.breakable(force: left_argument.comments.any?) q.format(AliasArgumentFormatter.new(right), stackable: false) end end end end |