Skip to content

Instantly share code, notes, and snippets.

@dmytro
Created November 29, 2011 06:45
Show Gist options
  • Save dmytro/1403742 to your computer and use it in GitHub Desktop.
Save dmytro/1403742 to your computer and use it in GitHub Desktop.
Simple debugging
class Object
require 'pp'
# Simple debugging method for ruby. It takes an object, prints it with time
# stamp and caller insformation, returns an object. So it can be instesreted
# into any chain or method calls.
#
# Program debug level can be set by either global variable $debug or
# environment setting ENV['DEBUG']
#
def debug *args
msg, level = '', 1
args.each do |x|
case x
when String then msg = x
when Fixnum then level = x
end
end
if [0, $debug, ENV['DEBUG']].map(&:to_i).max >= level
clr = File.basename(caller[1])
puts ["*****", Time.now, clr, msg.to_s].join ' --- '
pp self
end
return self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment