Skip to content

Instantly share code, notes, and snippets.

@milkfarm
Created September 4, 2009 01:12
Show Gist options
  • Save milkfarm/180663 to your computer and use it in GitHub Desktop.
Save milkfarm/180663 to your computer and use it in GitHub Desktop.
Method to dump variables in Ruby
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