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
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ VarField
constructor
A new instance of VarField.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:, comments: []) ⇒ VarField
Returns a new instance of VarField.
9494 9495 9496 9497 9498 |
# File 'lib/syntax_tree/node.rb', line 9494 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
9492 9493 9494 |
# File 'lib/syntax_tree/node.rb', line 9492 def comments @comments end |
#value ⇒ Object (readonly)
- nil | Const | CVar | GVar | Ident | IVar
-
the target of this node
9489 9490 9491 |
# File 'lib/syntax_tree/node.rb', line 9489 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
9500 9501 9502 |
# File 'lib/syntax_tree/node.rb', line 9500 def accept(visitor) visitor.visit_var_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9504 9505 9506 |
# File 'lib/syntax_tree/node.rb', line 9504 def child_nodes [value] end |
#deconstruct_keys(_keys) ⇒ Object
9510 9511 9512 |
# File 'lib/syntax_tree/node.rb', line 9510 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
9514 9515 9516 9517 9518 9519 9520 |
# File 'lib/syntax_tree/node.rb', line 9514 def format(q) if value == :nil q.text("nil") elsif value q.format(value) end end |