Load Path Find¶ ↑
Useful tools for looking for files on the $LOAD_PATH
DEPRECATED¶ ↑
This library is no longer maintained. Everything it does and so much more is now provided by github.com/joshbuddy/callsite. To get back load_path_find’s specific functionality, you can do the following
gem install 'callsite'
And in ruby
require 'load_path_find'
Now everything below will work as-is!
Usage¶ ↑
> require 'load_path_find' > $LOAD_PATH.find_file('set.rb') < "/opt/local/lib/ruby/1.8/set.rb"
.. Load a bunch of gems with spec directories ..
> $LOAD_PATH.find_all_files('../spec')
And you’ll get an array of matches.
> $LOAD_PATH.find_all_files('../spec') {|file| puts "here is a spec! #{file}"}
And now, even more awesome!
> $LOAD_PATH.add_current
.. adds the current path to your $LOAD_PATH
and.
> $LOAD_PATH.add_current!
.. adds the current path to the start of the $LOAD_PATH
And one more clever trick, Kernel#require_all
, lets you require all matching files.
Also, there is Kernel#require_next
which can be used to monkey patch on require:
# my_extension/stringio.rb require_next "stringio" StringIO.class_eval do # insert evil stuff here end # my_extension/setup.rb $LOAD_PATH.add_current! require "some_code_not_owned_by_me_maybe_requiring_stringio_oh_how_will_i_fool_them_all"