1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$LOADED_SCRIPTS = {}

def absrequire(file)
  found_candidate = false
  files = ["#{file.sub(/\.rb$/, '')}.rb", file].uniq
  
  $:.each do |load_path|
    files.each do |f|
      path = File.expand_path(File.join('.', load_path, f))
      
      if File.exists?(path)
        if $LOADED_SCRIPTS.has_key?(path)
          found_candidate = true
          break
        end
        $LOADED_SCRIPTS[path] = file
        return load(path)
      end
    end
  end
  return false if found_candidate
  raise LoadError, "no such file to load -- #{file}"
end