Skip to content

Instantly share code, notes, and snippets.

@luislavena
Created November 10, 2011 20:21
Show Gist options
  • Select an option

  • Save luislavena/1356075 to your computer and use it in GitHub Desktop.

Select an option

Save luislavena/1356075 to your computer and use it in GitHub Desktop.
name = "readline" # (the one you used in your require)
extensions = %w(rb so dll)
extensions.each do |ext|
expanded_path = $LOAD_PATH.map { |p| File.expand_path(p) }
result = catch(:found) do
expanded_path.each do |p|
f = "#{name}.#{ext}"
if File.exist? File.expand_path f, p
throw :found, [f, p]
# found, use this
end
end
nil
end
if result then
# The found file is then obtained a realpath (symlinks resolved)
# before adding to $LOADED_FEATURES
real = File.realpath(result[0], result[1])
puts "found: #{real}"
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment