Skip to content

Instantly share code, notes, and snippets.

@mxrguspxrt
Created March 21, 2012 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxrguspxrt/2146524 to your computer and use it in GitHub Desktop.
Save mxrguspxrt/2146524 to your computer and use it in GitHub Desktop.
Compare methods in different classes
def digest array
Digest::MD5.hexdigest array.to_s
end
def write file, array
File.open(file, 'w') { |f| f.write array.sort.to_json }
end
def read file
File.open(file, 'r') { |f| JSON.parse(f.read) }
end
def compare a, b
puts "count: #{a.count} #{b.count}"
puts "MD5s: #{digest(a)} #{digest(b)}"
if digest(a) != digest(b)
puts "Missing from A: " + b.select { |i| !a.include? i }.to_s
puts "Missing from B: " + a.select { |i| !b.include? i }.to_s
end
end
branch = 'liii_modularize'
klass = Liii
write "/tmp/#{klass.name}.methods.#{branch}", klass.methods
write "/tmp/#{klass.name}.new.methods.#{branch}", klass.new.methods
# comparing
branch_a = 'master'
branch_b = 'liii_modularize'
compare read("/tmp/#{klass.name}.methods.#{branch_a}"), read("/tmp/#{klass.name}.methods.#{branch_b}")
compare read("/tmp/#{klass.name}.new.methods.#{branch_a}"), read("/tmp/#{klass.name}.new.methods.#{branch_b}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment