Determining where in the inheritance chain a method is defined

Posted by Tim Connor Tue, 16 Dec 2008 19:19:00 GMT

Define in your .irbrc.

def Object.method_defined_where(method)
  self.ancestors.detect { |a| a.methods(false).include?(method.to_s) }
#=> IO

jbarnette and bougyman in #caboose helped me get it closer to actually working. It still probably needs some tuning. Feel free to fork and tweak the gist on method_defined_where, and then comment here.

Leave a comment