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, #pretty_print, #to_json
Constructor Details
#initialize(constant:, location:) ⇒ TopConstField
10689
10690
10691
10692
10693
|
# File 'lib/syntax_tree/node.rb', line 10689
def initialize(constant:, location:)
@constant = constant
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10687
10688
10689
|
# File 'lib/syntax_tree/node.rb', line 10687
def
@comments
end
|
#constant ⇒ Object
- Const
-
the constant being assigned
10684
10685
10686
|
# File 'lib/syntax_tree/node.rb', line 10684
def constant
@constant
end
|
Instance Method Details
#===(other) ⇒ Object
10725
10726
10727
|
# File 'lib/syntax_tree/node.rb', line 10725
def ===(other)
other.is_a?(TopConstField) && constant === other.constant
end
|
#accept(visitor) ⇒ Object
10695
10696
10697
|
# File 'lib/syntax_tree/node.rb', line 10695
def accept(visitor)
visitor.visit_top_const_field(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
10699
10700
10701
|
# File 'lib/syntax_tree/node.rb', line 10699
def child_nodes
[constant]
end
|
#copy(constant: nil, location: nil) ⇒ Object
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
|
# File 'lib/syntax_tree/node.rb', line 10703
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
10716
10717
10718
|
# File 'lib/syntax_tree/node.rb', line 10716
def deconstruct_keys(_keys)
{ constant: constant, location: location, comments: }
end
|
10720
10721
10722
10723
|
# File 'lib/syntax_tree/node.rb', line 10720
def format(q)
q.text("::")
q.format(constant)
end
|