Skip to content

Instantly share code, notes, and snippets.

@aphyr
Created August 24, 2009 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aphyr/174012 to your computer and use it in GitHub Desktop.
Save aphyr/174012 to your computer and use it in GitHub Desktop.
# From rails/activesupport/lib/active_support/dependencies.rb:333
# Ulysses forgets standard library, complains instead:
# http://dev.rubyonrails.org/changeset?new=trunk%2Factivesupport%2Flib%2Factive_support%2Fdependencies.rb%404728&old=trunk%2Factivesupport%2Flib%2Factive_support%2Fdependencies.rb%404681
# Search for a file in load_paths matching the provided suffix.
def search_for_file(path_suffix)
path_suffix = path_suffix + '.rb' unless path_suffix.ends_with? '.rb'
load_paths.each do |root|
path = File.join(root, path_suffix)
return path if File.file? path
end
nil # Gee, I sure wish we had first_match ;-)
end
# Hint: you were looking for Array#find.
# http://www.ruby-doc.org/core/classes/Enumerable.html#M003122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment