Class: SyntaxTree::VarRef
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.
-
#value ⇒ Object
readonly
- Const | CVar | GVar | Ident | IVar | Kw
-
the value of this node.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ 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.
10658 10659 10660 10661 10662 |
# File 'lib/syntax_tree/node.rb', line 10658 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
10656 10657 10658 |
# File 'lib/syntax_tree/node.rb', line 10656 def comments @comments end |
#value ⇒ Object (readonly)
- Const | CVar | GVar | Ident | IVar | Kw
-
the value of this node
10653 10654 10655 |
# File 'lib/syntax_tree/node.rb', line 10653 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10664 10665 10666 |
# File 'lib/syntax_tree/node.rb', line 10664 def child_nodes [value] end |
#deconstruct_keys(keys) ⇒ Object
10670 10671 10672 |
# File 'lib/syntax_tree/node.rb', line 10670 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
10674 10675 10676 |
# File 'lib/syntax_tree/node.rb', line 10674 def format(q) q.format(value) end |
#pretty_print(q) ⇒ Object
10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 |
# File 'lib/syntax_tree/node.rb', line 10678 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
10689 10690 10691 10692 10693 |
# File 'lib/syntax_tree/node.rb', line 10689 def to_json(*opts) { type: :var_ref, value: value, loc: location, cmts: comments }.to_json( *opts ) end |