Created
November 10, 2011 20:26
-
-
Save luislavena/1356101 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $count = 0 | |
| class File < IO | |
| class << self | |
| alias_method :orig_expand_path, :expand_path | |
| def expand_path(file_name, dir_string = nil) | |
| $count += 1 | |
| orig_expand_path file_name, dir_string | |
| end | |
| end | |
| end | |
| 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 | |
| puts "size of $LOAD_PATH: #{$LOAD_PATH.size}" | |
| puts "calls to File.expand_path: #{$count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment