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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:) ⇒ VarField
constructor
A new instance of VarField.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ VarField
Returns a new instance of VarField.
11353 11354 11355 11356 11357 |
# File 'lib/syntax_tree/node.rb', line 11353 def initialize(value:, location:) @value = value @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11351 11352 11353 |
# File 'lib/syntax_tree/node.rb', line 11351 def comments @comments end |
#value ⇒ Object (readonly)
- nil | Const | CVar | GVar | Ident | IVar
-
the target of this node
11348 11349 11350 |
# File 'lib/syntax_tree/node.rb', line 11348 def value @value end |
Instance Method Details
#===(other) ⇒ Object
11392 11393 11394 |
# File 'lib/syntax_tree/node.rb', line 11392 def ===(other) other.is_a?(VarField) && value === other.value end |
#accept(visitor) ⇒ Object
11359 11360 11361 |
# File 'lib/syntax_tree/node.rb', line 11359 def accept(visitor) visitor.visit_var_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11363 11364 11365 |
# File 'lib/syntax_tree/node.rb', line 11363 def child_nodes [value] end |
#copy(value: nil, location: nil) ⇒ Object
11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 |
# File 'lib/syntax_tree/node.rb', line 11367 def copy(value: nil, location: nil) node = VarField.new( value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
11380 11381 11382 |
# File 'lib/syntax_tree/node.rb', line 11380 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
11384 11385 11386 11387 11388 11389 11390 |
# File 'lib/syntax_tree/node.rb', line 11384 def format(q) if value == :nil q.text("nil") elsif value q.format(value) end end |