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.
12732 12733 12734 12735 12736 12737 |
# File 'lib/syntax_tree.rb', line 12732 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
12730 12731 12732 |
# File 'lib/syntax_tree.rb', line 12730 def comments @comments end |
#left ⇒ Object (readonly)
- GVar
-
the new alias of the variable
12721 12722 12723 |
# File 'lib/syntax_tree.rb', line 12721 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12727 12728 12729 |
# File 'lib/syntax_tree.rb', line 12727 def location @location end |
#right ⇒ Object (readonly)
- Backref | GVar
-
the current name of the variable to be aliased
12724 12725 12726 |
# File 'lib/syntax_tree.rb', line 12724 def right @right end |
Instance Method Details
#child_nodes ⇒ Object
12739 12740 12741 |
# File 'lib/syntax_tree.rb', line 12739 def child_nodes [left, right] end |
#format(q) ⇒ Object
12743 12744 12745 12746 12747 12748 12749 12750 |
# File 'lib/syntax_tree.rb', line 12743 def format(q) keyword = "alias " q.text(keyword) q.format(left) q.text(" ") q.format(right) end |
#pretty_print(q) ⇒ Object
12752 12753 12754 12755 12756 12757 12758 12759 12760 12761 12762 12763 12764 |
# File 'lib/syntax_tree.rb', line 12752 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
12766 12767 12768 12769 12770 12771 12772 12773 12774 |
# File 'lib/syntax_tree.rb', line 12766 def to_json(*opts) { type: :var_alias, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |