Class: SyntaxTree::VarAlias
- Inherits:
-
Object
- Object
- SyntaxTree::VarAlias
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#right ⇒ Object
readonly
- Backref | GVar
-
the current name of the variable to be aliased.
Instance Method Summary collapse
- #child_nodes ⇒ 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.
12651 12652 12653 12654 12655 12656 |
# File 'lib/syntax_tree.rb', line 12651 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
12649 12650 12651 |
# File 'lib/syntax_tree.rb', line 12649 def comments @comments end |
#left ⇒ Object (readonly)
- GVar
-
the new alias of the variable
12640 12641 12642 |
# File 'lib/syntax_tree.rb', line 12640 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12646 12647 12648 |
# File 'lib/syntax_tree.rb', line 12646 def location @location end |
#right ⇒ Object (readonly)
- Backref | GVar
-
the current name of the variable to be aliased
12643 12644 12645 |
# File 'lib/syntax_tree.rb', line 12643 def right @right end |
Instance Method Details
#child_nodes ⇒ Object
12658 12659 12660 |
# File 'lib/syntax_tree.rb', line 12658 def child_nodes [left, right] end |
#format(q) ⇒ Object
12662 12663 12664 12665 12666 12667 12668 12669 |
# File 'lib/syntax_tree.rb', line 12662 def format(q) keyword = "alias " q.text(keyword) q.format(left) q.text(" ") q.format(right) end |
#pretty_print(q) ⇒ Object
12671 12672 12673 12674 12675 12676 12677 12678 12679 12680 12681 12682 12683 |
# File 'lib/syntax_tree.rb', line 12671 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
12685 12686 12687 12688 12689 12690 12691 12692 12693 |
# File 'lib/syntax_tree.rb', line 12685 def to_json(*opts) { type: :var_alias, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |