Skip to content

Instantly share code, notes, and snippets.

@shadoi
Created October 2, 2010 03:16
Show Gist options
  • Save shadoi/607234 to your computer and use it in GitHub Desktop.
Save shadoi/607234 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_by_owner
output = {}
output[:private_methods] = {}
output[:instance_methods] = {}
output[:protected_methods] = {}
self.private_methods.each do |m|
key = self.method(m.to_sym).owner.to_s
output[:private_methods][key] ||= []
output[:private_methods][key] << m.to_sym
end
self.instance_methods.each do |m|
key = self.instance_method(m.to_sym).owner.to_s
output[:instance_methods][key] ||= []
output[:instance_methods][key] << m.to_sym
end
self.protected_methods.each do |m|
key = self.method(m.to_sym).owner.to_s
output[:protected_methods][key] ||=[]
output[:protected_methods][key] << m.to_sym
end
return output
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment