Class: SyntaxTree::VarRef
- Inherits:
-
Object
- Object
- SyntaxTree::VarRef
- Defined in:
- lib/syntax_tree.rb
Overview
VarRef represents a variable reference.
true
This can be a plain local variable like the example above. It can also be a constant, a class variable, a global variable, an instance variable, a keyword (like self
, nil
, true
, or false
), or a numbered block variable.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- Const | CVar | GVar | Ident | IVar | Kw
-
the value of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ VarRef
constructor
A new instance of VarRef.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ VarRef
Returns a new instance of VarRef.
12872 12873 12874 12875 12876 |
# File 'lib/syntax_tree.rb', line 12872 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12870 12871 12872 |
# File 'lib/syntax_tree.rb', line 12870 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12867 12868 12869 |
# File 'lib/syntax_tree.rb', line 12867 def location @location end |
#value ⇒ Object (readonly)
- Const | CVar | GVar | Ident | IVar | Kw
-
the value of this node
12864 12865 12866 |
# File 'lib/syntax_tree.rb', line 12864 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
12878 12879 12880 |
# File 'lib/syntax_tree.rb', line 12878 def child_nodes [value] end |
#format(q) ⇒ Object
12882 12883 12884 |
# File 'lib/syntax_tree.rb', line 12882 def format(q) q.format(value) end |
#pretty_print(q) ⇒ Object
12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 |
# File 'lib/syntax_tree.rb', line 12886 def pretty_print(q) q.group(2, "(", ")") do q.text("var_ref") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
12897 12898 12899 12900 12901 |
# File 'lib/syntax_tree.rb', line 12897 def to_json(*opts) { type: :var_ref, value: value, loc: location, cmts: comments }.to_json( *opts ) end |