class Reference
An Ruby-specific reference which can be resolved to zero or more definitions.
Definitions
def self.from_const(node, language)
Create a reference from a constant node.
Signature
-
parameter
node
Prism::Node
The constant node.
-
parameter
language
Language
The language instance.
Implementation
def self.from_const(node, language)
lexical_path = append_const(node)
return self.new(node.location.slice, language, lexical_path)
end
def self.append_const(node, path = [])
Append a constant node to the path.
Signature
-
parameter
node
Prism::Node
The constant node.
-
parameter
path
Array
The path to append to.
Implementation
def self.append_const(node, path = [])
case node.type
when :constant_read_node
path << [nil, node.name.to_s]
when :constant_path_node
if node.parent
append_const(node.parent, path)
path << ["::", node.name.to_s]
else
path << [nil, node.name.to_s]
end
when :call_node
# For call nodes like Tuple(...), treat them as constant references
if node.receiver.nil?
path << [nil, node.name.to_s]
else
append_const(node.receiver, path)
path << [".", node.name.to_s]
end
else
raise ArgumentError, "Could not determine reference for #{node.type}!"
end
return path
end
def split(text)
Split a Ruby identifier into prefix and name components.
Signature
-
parameter
text
String
The text to split.
Implementation
def split(text)
text.scan(/(::|\.|#|:)?([^:.#]+)/)
end