Skip to content

Instantly share code, notes, and snippets.

@heftig
Forked from shadoi/Kernel.methods
Created October 2, 2010 03:23
Show Gist options
  • Save heftig/607241 to your computer and use it in GitHub Desktop.
Save heftig/607241 to your computer and use it in GitHub Desktop.
# Returns a hash of methods organized by their owner and method type.
module Kernel
def methods
output = {}
syms = [:public_methods, :protected_methods, :private_methods]
syms.each do |sym|
output[sym] = {}
send(sym).each do |m|
key = self.method(m).owner
output[sym][key] ||= []
output[sym][key] << m
end
end
output
end
end
class Module
def instance_methods
output = {}
syms = [:public_instance_methods, :protected_instance_methods, :private_instance_methods]
syms.each do |sym|
output[sym] = {}
send(sym).each do |m|
key = self.instance_method(m).owner
output[sym][key] ||= []
output[sym][key] << m
end
end
output
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment