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.
12864 12865 12866 12867 12868 12869 |
# File 'lib/syntax_tree.rb', line 12864 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
12862 12863 12864 |
# File 'lib/syntax_tree.rb', line 12862 def comments @comments end |
#left ⇒ Object (readonly)
- GVar
-
the new alias of the variable
12853 12854 12855 |
# File 'lib/syntax_tree.rb', line 12853 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12859 12860 12861 |
# File 'lib/syntax_tree.rb', line 12859 def location @location end |
#right ⇒ Object (readonly)
- Backref | GVar
-
the current name of the variable to be aliased
12856 12857 12858 |
# File 'lib/syntax_tree.rb', line 12856 def right @right end |
Instance Method Details
#child_nodes ⇒ Object
12871 12872 12873 |
# File 'lib/syntax_tree.rb', line 12871 def child_nodes [left, right] end |
#format(q) ⇒ Object
12875 12876 12877 12878 12879 12880 12881 12882 |
# File 'lib/syntax_tree.rb', line 12875 def format(q) keyword = "alias " q.text(keyword) q.format(left) q.text(" ") q.format(right) end |
#pretty_print(q) ⇒ Object
12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 |
# File 'lib/syntax_tree.rb', line 12884 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
12898 12899 12900 12901 12902 12903 12904 12905 12906 |
# File 'lib/syntax_tree.rb', line 12898 def to_json(*opts) { type: :var_alias, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |