Class: SyntaxTree::VarField
Overview
VarField represents a variable that is being assigned a value. As such, it is always a child of an assignment type node.
variable = value
In the example above, the VarField node represents the variable token.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- nil | Const | CVar | GVar | Ident | IVar
-
the target 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: []) ⇒ VarField
constructor
A new instance of VarField.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ VarField
Returns a new instance of VarField.
10605 10606 10607 10608 10609 |
# File 'lib/syntax_tree/node.rb', line 10605 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
10603 10604 10605 |
# File 'lib/syntax_tree/node.rb', line 10603 def comments @comments end |
#value ⇒ Object (readonly)
- nil | Const | CVar | GVar | Ident | IVar
-
the target of this node
10600 10601 10602 |
# File 'lib/syntax_tree/node.rb', line 10600 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10611 10612 10613 |
# File 'lib/syntax_tree/node.rb', line 10611 def child_nodes [value] end |
#deconstruct_keys(keys) ⇒ Object
10617 10618 10619 |
# File 'lib/syntax_tree/node.rb', line 10617 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
10621 10622 10623 |
# File 'lib/syntax_tree/node.rb', line 10621 def format(q) q.format(value) if value end |
#pretty_print(q) ⇒ Object
10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 |
# File 'lib/syntax_tree/node.rb', line 10625 def pretty_print(q) q.group(2, "(", ")") do q.text("var_field") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
10636 10637 10638 10639 10640 |
# File 'lib/syntax_tree/node.rb', line 10636 def to_json(*opts) { type: :var_field, value: value, loc: location, cmts: comments }.to_json( *opts ) end |