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
Constructor Details
#initialize(value:, location:, comments: []) ⇒ VarField
Returns a new instance of VarField.
9217 9218 9219 9220 9221 |
# File 'lib/syntax_tree/node.rb', line 9217 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
9215 9216 9217 |
# File 'lib/syntax_tree/node.rb', line 9215 def comments @comments end |
#value ⇒ Object (readonly)
- nil | Const | CVar | GVar | Ident | IVar
-
the target of this node
9212 9213 9214 |
# File 'lib/syntax_tree/node.rb', line 9212 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
9223 9224 9225 |
# File 'lib/syntax_tree/node.rb', line 9223 def accept(visitor) visitor.visit_var_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9227 9228 9229 |
# File 'lib/syntax_tree/node.rb', line 9227 def child_nodes [value] end |
#deconstruct_keys(keys) ⇒ Object
9233 9234 9235 |
# File 'lib/syntax_tree/node.rb', line 9233 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
9237 9238 9239 9240 9241 9242 9243 |
# File 'lib/syntax_tree/node.rb', line 9237 def format(q) if value == :nil q.text("nil") elsif value q.format(value) end end |