Class: SyntaxTree::TopConstField
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::TopConstField
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
TopConstField is always the child node of some kind of assignment. It represents when you’re assigning to a constant that is being referenced at the top level.
::Constant = value
Instance Attribute Summary collapse
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(constant:, location:) ⇒ TopConstField
Returns a new instance of TopConstField.
10813
10814
10815
10816
10817
|
# File 'lib/syntax_tree/node.rb', line 10813
def initialize(constant:, location:)
@constant = constant
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10811
10812
10813
|
# File 'lib/syntax_tree/node.rb', line 10811
def
@comments
end
|
#constant ⇒ Object
- Const
-
the constant being assigned
10808
10809
10810
|
# File 'lib/syntax_tree/node.rb', line 10808
def constant
@constant
end
|
Instance Method Details
#===(other) ⇒ Object
10849
10850
10851
|
# File 'lib/syntax_tree/node.rb', line 10849
def ===(other)
other.is_a?(TopConstField) && constant === other.constant
end
|
#accept(visitor) ⇒ Object
10819
10820
10821
|
# File 'lib/syntax_tree/node.rb', line 10819
def accept(visitor)
visitor.visit_top_const_field(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
10823
10824
10825
|
# File 'lib/syntax_tree/node.rb', line 10823
def child_nodes
[constant]
end
|
#copy(constant: nil, location: nil) ⇒ Object
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
|
# File 'lib/syntax_tree/node.rb', line 10827
def copy(constant: nil, location: nil)
node =
TopConstField.new(
constant: constant || self.constant,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
10840
10841
10842
|
# File 'lib/syntax_tree/node.rb', line 10840
def deconstruct_keys(_keys)
{ constant: constant, location: location, comments: }
end
|
10844
10845
10846
10847
|
# File 'lib/syntax_tree/node.rb', line 10844
def format(q)
q.text("::")
q.format(constant)
end
|