Created
November 29, 2011 06:45
-
-
Save dmytro/1403742 to your computer and use it in GitHub Desktop.
Simple debugging
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
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