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.
-
#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 (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.
10970 10971 10972 10973 10974 10975 |
# File 'lib/syntax_tree/node.rb', line 10970 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
10968 10969 10970 |
# File 'lib/syntax_tree/node.rb', line 10968 def comments @comments end |
#left ⇒ Object (readonly)
- GVar
-
the new alias of the variable
10959 10960 10961 |
# File 'lib/syntax_tree/node.rb', line 10959 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10965 10966 10967 |
# File 'lib/syntax_tree/node.rb', line 10965 def location @location end |
#right ⇒ Object (readonly)
- Backref | GVar
-
the current name of the variable to be aliased
10962 10963 10964 |
# File 'lib/syntax_tree/node.rb', line 10962 def right @right end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10977 10978 10979 |
# File 'lib/syntax_tree/node.rb', line 10977 def child_nodes [left, right] end |
#deconstruct_keys(keys) ⇒ Object
10983 10984 10985 |
# File 'lib/syntax_tree/node.rb', line 10983 def deconstruct_keys(keys) { left: left, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
10987 10988 10989 10990 10991 10992 10993 10994 |
# File 'lib/syntax_tree/node.rb', line 10987 def format(q) keyword = "alias " q.text(keyword) q.format(left) q.text(" ") q.format(right) end |
#pretty_print(q) ⇒ Object
10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 |
# File 'lib/syntax_tree/node.rb', line 10996 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
11010 11011 11012 11013 11014 11015 11016 11017 11018 |
# File 'lib/syntax_tree/node.rb', line 11010 def to_json(*opts) { type: :var_alias, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |