Created
May 30, 2012 19:39
-
-
Save RoUS/2838483 to your computer and use it in GitHub Desktop.
Keep your 'debugger' statements in even when testing on hosts lacking the gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This snippet allows you to sprinkle your code with #debugger references | |
# even if the ruby-debug gem isn't installed (or there's some other error | |
# encountered loading it). | |
# | |
begin | |
require('ruby-debug') | |
Debugger.start | |
rescue Exception => e | |
unless (Kernel.method_defined?(:debugger)) | |
Kernel.module_eval do | |
define_method(:debugger) do | |
msg = ("#{$0}: ruby-debug gem not loaded, debugger not available\n" + | |
"\t#{e.class.name}: #{e.message}\n" + | |
"\t") | |
warn(msg + caller.first) | |
return nil | |
end | |
module_function(:debugger) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment