Created
January 19, 2011 16:16
-
-
Save codekitchen/786380 to your computer and use it in GitHub Desktop.
view a diff of two ruby objects using pp and your difftool
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
$vdiff_difftool = 'ksdiff' | |
require 'pp' | |
class Object | |
def vdiff(other) | |
require 'tempfile' | |
t1 = Tempfile.new(['vdiff', '.rb']) | |
t2 = Tempfile.new(['vdiff', '.rb']) | |
PP.pp self, t1 | |
PP.pp other, t2 | |
`#{$vdiff_difftool} #{t1.path} #{t2.path}` | |
t1.close | |
t2.close | |
end | |
end | |
class Hash | |
def each_sorted_pair | |
self.keys.sort.each do |k| | |
yield k, self[k] | |
end | |
end | |
end | |
module PP::PPMethods | |
def pp_hash(obj) | |
group(1, '{', '}') { | |
seplist(obj, nil, :each_sorted_pair) {|k, v| | |
group { | |
pp k | |
text '=>' | |
group(1) { | |
breakable '' | |
pp v | |
} | |
} | |
} | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment