From: Leslie Viljoen Date: 2005-11-07T16:23:14+09:00 Subject: Re: Rails and dirty namespaces Stefan Lang wrote: >On Friday 04 November 2005 09:56, Leslie Viljoen wrote: > > >>Hey people >> >>Just had quite an experience deploying my Rails app to Textdrive - >>the Nitro gem was installed and there was a class in the Glue >>module with the same name as my model... it took me two days to >>figure it out! >> >>What I don't understand is how Glue got included in my project, >>since all the Rails code I looked at makes no mention of it and I >>didn't 'require' it. Running irb, the offending class was not >>there, running script/console, it was included! >> >>How do I track down where it was included? Is there a way to list >>the files that have been 'require'd? Is there a way to list all >>classes available - >>and is there a way to tell if a class is 'custom' versus included >>with the base Ruby installation? >> >>Les >> >> > >Save this in a file "loaded.rb": >-------------------------------- >require 'rbconfig' > >def find_ruby_lib(name) > $LOAD_PATH.each { |dir| > fn = File.join(dir, name) > return dir, fn if File.exist? fn > } > raise "no such library loaded -- #{name}" >end > >def is_std_library_dir?(dir) > dir == Config::CONFIG["rubylibdir"] || > dir == Config::CONFIG["archdir"] >end > >def print_loaded_libs > $LOADED_FEATURES.each { |lib_name| > dir, fn = find_ruby_lib(lib_name) > puts lib_name > puts " path: #{fn}" > puts " Standard Library" if is_std_library_dir?(dir) > } >end >-------------------------------- >Then, before exiting (or at least after all require's) >do: > require 'loaded' > print_loaded_libs > >Example: > ruby -r optparse -r loaded -e 'print_loaded_libs' > optparse.rb > path: /usr/local/lib/ruby/1.8/optparse.rb > Standard Library > loaded.rb > path: ./loaded.rb > rbconfig.rb > path: /usr/local/lib/ruby/1.8/i686-linux/rbconfig.rb > Standard Library > >HTH, > Stefan > > > Thanks - great solution!