Class: SyntaxTree::VarAlias
Overview
VarAlias represents when you’re using the alias keyword with global variable arguments.
alias $new $old
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#left ⇒ Object
readonly
- GVar
-
the new alias of the variable.
-
#right ⇒ Object
readonly
- Backref | GVar
-
the current name of the variable to be aliased.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(left:, right:, location:, comments: []) ⇒ VarAlias
constructor
A new instance of VarAlias.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(left:, right:, location:, comments: []) ⇒ VarAlias
Returns a new instance of VarAlias.
10541 10542 10543 10544 10545 10546 |
# File 'lib/syntax_tree/node.rb', line 10541 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
10539 10540 10541 |
# File 'lib/syntax_tree/node.rb', line 10539 def comments @comments end |
#left ⇒ Object (readonly)
- GVar
-
the new alias of the variable
10533 10534 10535 |
# File 'lib/syntax_tree/node.rb', line 10533 def left @left end |
#right ⇒ Object (readonly)
- Backref | GVar
-
the current name of the variable to be aliased
10536 10537 10538 |
# File 'lib/syntax_tree/node.rb', line 10536 def right @right end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10548 10549 10550 |
# File 'lib/syntax_tree/node.rb', line 10548 def child_nodes [left, right] end |
#deconstruct_keys(keys) ⇒ Object
10554 10555 10556 |
# File 'lib/syntax_tree/node.rb', line 10554 def deconstruct_keys(keys) { left: left, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
10558 10559 10560 10561 10562 10563 10564 10565 |
# File 'lib/syntax_tree/node.rb', line 10558 def format(q) keyword = "alias " q.text(keyword) q.format(left) q.text(" ") q.format(right) end |
#pretty_print(q) ⇒ Object
10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 |
# File 'lib/syntax_tree/node.rb', line 10567 def pretty_print(q) q.group(2, "(", ")") do q.text("var_alias") q.breakable q.pp(left) q.breakable q.pp(right) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
10581 10582 10583 10584 10585 10586 10587 10588 10589 |
# File 'lib/syntax_tree/node.rb', line 10581 def to_json(*opts) { type: :var_alias, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |