Skip to content

Instantly share code, notes, and snippets.

View dougbarth's full-sized avatar

Doug Barth dougbarth

View GitHub Profile
1 class Object
2 # Returns a hash where the key is a message that this object
3 # responds to and the value is the first object that responded
4 # to that message.
5 def first_responders
6 methods_hash = {}
7 self.class.instance_methods.each {|m| methods_hash[m] = self}
8 self.class.ancestors.each do |ancestor|
9 ancestor.instance_methods.each {|m| methods_hash[m] = ancestor}
10 end