Skip to content

Instantly share code, notes, and snippets.

@marcandre
Last active December 14, 2015 02:39
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 marcandre/5015789 to your computer and use it in GitHub Desktop.
Save marcandre/5015789 to your computer and use it in GitHub Desktop.
# 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