Last active
December 14, 2015 02:39
-
-
Save marcandre/5015789 to your computer and use it in GitHub Desktop.
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
# Quick and dirty script to compare builtin methods between two rubyies | |
# Usage: | |
# | |
# ruby_old digest.rb | ruby_new digest.rb | |
def class_signature(klass) | |
Hash[ | |
{instance: klass, singleton: klass.singleton_class}.to_a | |
.product([:private, :public, :protected]) | |
.map{ |(level, obj), access| ["#{access} #{level} methods", obj.send("#{access}_instance_methods", false)] } | |
] # Argh, when will Matz accept Enumerable#associate? | |
end | |
dict = Hash[ | |
ObjectSpace.each_object(Module) | |
.select(&:name) # reject anonymous classes, not sure why there is one in 2.0.0 | |
.map{|k| [k.name, class_signature(k)]} | |
] # I really hate Hash[] | |
class Hash | |
def -(other) # dirty hack to recursively diff hashes, with arrays leaves | |
Hash[ | |
map do |key, val| | |
[key, other.has_key?(key) ? val - other[key] : 'all'] | |
end | |
] # Did I say how much we need a way to convert Enumerables to Hash? | |
.reject{|_key, val| val.empty?} | |
end | |
end | |
require 'yaml' | |
require 'pp' | |
if $stdin.tty? | |
YAML.dump dict, $stdout | |
else | |
other_dict = YAML.load($stdin) | |
pp added: dict - other_dict, | |
removed: other_dict - dict | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment