find_symbol(symbol, method = nil)
public
Look up symbol. If method is non-nil, then we assume the
symbol references a module that contains that method.
Show source
def find_symbol(symbol, method = nil)
result = nil
case symbol
when /^::(.*)/ then
result = toplevel.find_symbol($1)
when /::/ then
modules = symbol.split(/::/)
unless modules.empty? then
module_name = modules.shift
result = find_module_named(module_name)
if result then
modules.each do |name|
result = result.find_module_named(name)
break unless result
end
end
end
else
if method
result = find_module_named(symbol)
else
result = find_local_symbol(symbol)
if result.nil?
if symbol =~ /^[A-Z]/
result = parent
while result && result.name != symbol
result = result.parent
end
end
end
end
end
if result and method then
fail unless result.respond_to? :find_local_symbol
result = result.find_local_symbol(method)
end
result
end