Class: SyntaxTree::VarField
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::VarField
show all
- Defined in:
- lib/syntax_tree/node.rb
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
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ VarField
11362
11363
11364
11365
11366
|
# File 'lib/syntax_tree/node.rb', line 11362
def initialize(value:, location:)
@value = value
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11360
11361
11362
|
# File 'lib/syntax_tree/node.rb', line 11360
def
end
|
#value ⇒ Object
- nil | Const | CVar | GVar | Ident | IVar
-
the target of this node
11357
11358
11359
|
# File 'lib/syntax_tree/node.rb', line 11357
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
11401
11402
11403
|
# File 'lib/syntax_tree/node.rb', line 11401
def ===(other)
other.is_a?(VarField) && value === other.value
end
|
#accept(visitor) ⇒ Object
11368
11369
11370
|
# File 'lib/syntax_tree/node.rb', line 11368
def accept(visitor)
visitor.visit_var_field(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
11372
11373
11374
|
# File 'lib/syntax_tree/node.rb', line 11372
def child_nodes
[value]
end
|
#copy(value: nil, location: nil) ⇒ Object
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
|
# File 'lib/syntax_tree/node.rb', line 11376
def copy(value: nil, location: nil)
node =
VarField.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
11389
11390
11391
|
# File 'lib/syntax_tree/node.rb', line 11389
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
11393
11394
11395
11396
11397
11398
11399
|
# File 'lib/syntax_tree/node.rb', line 11393
def format(q)
if value == :nil
q.text("nil")
elsif value
q.format(value)
end
end
|