Skip to content

Instantly share code, notes, and snippets.

@codekitchen
Created January 19, 2011 16:16
Show Gist options
  • Save codekitchen/786380 to your computer and use it in GitHub Desktop.
Save codekitchen/786380 to your computer and use it in GitHub Desktop.
view a diff of two ruby objects using pp and your difftool
$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