Created
September 4, 2009 01:12
-
-
Save milkfarm/180663 to your computer and use it in GitHub Desktop.
Method to dump variables in Ruby
This file contains hidden or 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
def debug(msg, object) | |
print "# [debug] #{msg} " | |
begin | |
Marshal::dump(object) | |
raise if object.nil? | |
puts h(object.to_yaml) | |
rescue Exception => e # errors from Marshal or YAML | |
# Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback | |
puts "--- #{object.inspect}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment