Class: SyntaxTree::ConstRef
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::ConstRef
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
ConstRef represents the name of the constant being used in a class or module declaration.
class Container
end
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:) ⇒ ConstRef
Returns a new instance of ConstRef.
3999
4000
4001
4002
4003
|
# File 'lib/syntax_tree/node.rb', line 3999
def initialize(constant:, location:)
@constant = constant
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3997
3998
3999
|
# File 'lib/syntax_tree/node.rb', line 3997
def
@comments
end
|
#constant ⇒ Object
- Const
-
the constant itself
3994
3995
3996
|
# File 'lib/syntax_tree/node.rb', line 3994
def constant
@constant
end
|
Instance Method Details
#===(other) ⇒ Object
4034
4035
4036
|
# File 'lib/syntax_tree/node.rb', line 4034
def ===(other)
other.is_a?(ConstRef) && constant === other.constant
end
|
#accept(visitor) ⇒ Object
4005
4006
4007
|
# File 'lib/syntax_tree/node.rb', line 4005
def accept(visitor)
visitor.visit_const_ref(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
4009
4010
4011
|
# File 'lib/syntax_tree/node.rb', line 4009
def child_nodes
[constant]
end
|
#copy(constant: nil, location: nil) ⇒ Object
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
|
# File 'lib/syntax_tree/node.rb', line 4013
def copy(constant: nil, location: nil)
node =
ConstRef.new(
constant: constant || self.constant,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
4026
4027
4028
|
# File 'lib/syntax_tree/node.rb', line 4026
def deconstruct_keys(_keys)
{ constant: constant, location: location, comments: }
end
|
4030
4031
4032
|
# File 'lib/syntax_tree/node.rb', line 4030
def format(q)
q.format(constant)
end
|