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.
13004 13005 13006 13007 13008 |
# File 'lib/syntax_tree.rb', line 13004 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
13002 13003 13004 |
# File 'lib/syntax_tree.rb', line 13002 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12999 13000 13001 |
# File 'lib/syntax_tree.rb', line 12999 def location @location end |
#value ⇒ Object (readonly)
- Const | CVar | GVar | Ident | IVar | Kw
-
the value of this node
12996 12997 12998 |
# File 'lib/syntax_tree.rb', line 12996 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
13010 13011 13012 |
# File 'lib/syntax_tree.rb', line 13010 def child_nodes [value] end |
#format(q) ⇒ Object
13014 13015 13016 |
# File 'lib/syntax_tree.rb', line 13014 def format(q) q.format(value) end |
#pretty_print(q) ⇒ Object
13018 13019 13020 13021 13022 13023 13024 13025 13026 13027 |
# File 'lib/syntax_tree.rb', line 13018 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
13029 13030 13031 13032 13033 |
# File 'lib/syntax_tree.rb', line 13029 def to_json(*opts) { type: :var_ref, value: value, loc: location, cmts: comments }.to_json( *opts ) end |