Skip to content

Instantly share code, notes, and snippets.

@vjt
Created January 11, 2011 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjt/774431 to your computer and use it in GitHub Desktop.
Save vjt/774431 to your computer and use it in GitHub Desktop.
ruby require tree
# Wanna debug who the hell is requiring that damn gem
# you don't wanna see on earth? Here we go! :-)
#
# debugger rescue nil is required (ha ha) because, if
# you require ruby-debug, the debugger method will be
# defined *before* all debugger components are loaded
#
# Please note that, because this method is defined in
# Object, caller(0) will contain [$0,$0], thus you'll
# have to step inside the original require method and
# then call caller(0).
#
$require_level = []
def self.require(file)
$require_level << '='
debugger rescue nil if file.to_s == 'rake' || file.to_s == 'tsort'
puts "#{$require_level.join} #{file.inspect} from #{caller(0)[1]}"
ret = super(file)
$require_level.pop
return ret
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment