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 | :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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ VarField
11545
11546
11547
11548
11549
|
# File 'lib/syntax_tree/node.rb', line 11545
def initialize(value:, location:)
@value = value
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11543
11544
11545
|
# File 'lib/syntax_tree/node.rb', line 11543
def
end
|
#value ⇒ Object
- nil | :nil | Const | CVar | GVar | Ident | IVar
-
the target of this node
11540
11541
11542
|
# File 'lib/syntax_tree/node.rb', line 11540
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
11584
11585
11586
|
# File 'lib/syntax_tree/node.rb', line 11584
def ===(other)
other.is_a?(VarField) && value === other.value
end
|
#accept(visitor) ⇒ Object
11551
11552
11553
|
# File 'lib/syntax_tree/node.rb', line 11551
def accept(visitor)
visitor.visit_var_field(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
11555
11556
11557
|
# File 'lib/syntax_tree/node.rb', line 11555
def child_nodes
value == :nil ? [] : [value]
end
|
#copy(value: nil, location: nil) ⇒ Object
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
|
# File 'lib/syntax_tree/node.rb', line 11559
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
11572
11573
11574
|
# File 'lib/syntax_tree/node.rb', line 11572
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
11576
11577
11578
11579
11580
11581
11582
|
# File 'lib/syntax_tree/node.rb', line 11576
def format(q)
if value == :nil
q.text("nil")
elsif value
q.format(value)
end
end
|