Easily Debug Ruby Loading Issues

Curious which files and gems are getting loaded and why?

def require path
  puts "require: (#{path}) #{caller[0]}"

def gem(*args)
  puts "gem: #{args.inspect} #{caller[0]}"

Save it off as require_inspector.rb, and then run it with ruby -r require_inspector.rb file_name.


1 Comment

Filed under ruby

One response to “Easily Debug Ruby Loading Issues

  1. Good one! I had to comment out the gem method override though because of this (starting up a Rails 2.3.11 server):

    Bill$ ruby -r ./require_inspector.rb ./script/server | tee > requirements.txt
    /Library/Ruby/Site/1.8/rubygems.rb:1245:in `remove_method’: method `gem’ not defined in Kernel (NameError)
    from /Library/Ruby/Site/1.8/rubygems.rb:1245
    from ./require_inspector.rb:4:in `require’

    With the gem method commented out though, I was able to get the information I needed from the require override. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s