Skip to content

Instantly share code, notes, and snippets.

@RoUS
Created May 30, 2012 19:39
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 RoUS/2838483 to your computer and use it in GitHub Desktop.
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 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