From: Adam Salter Date: 2007-12-13T08:15:08+09:00 Subject: Inheritance and meta-classes Hi all, OK. I'm trying to work out where a method is defined in Rails. It's in a test, and the specific function that's being called is 'post', but my question is not a Rails question, it's Ruby. How do I find where a function is defined in the inheritance tree? Because of metaclass inheritance being cyclical I don't know where to stop looking. I made the following as a test but I still can't find the function being called so I'm guessing I'm missing some of the inheritance tree... module Debugs def find_respond_to_in_class_heirarchy(obj, method) if obj.respond_to?(:superclass) arr = find_respond_to_in_class_heirarchy(obj.superclass, method) arr.unshift([obj.class.respond_to?(method), obj.metaclass.respond_to?(method), obj.superclass.respond_to?(method)]) elsif obj.nil? arr = [[nil.class.respond_to?(method), nil.metaclass.respond_to? (method), NoMethodError]] else arr = find_respond_to_in_class_heirarchy(obj.class, method) arr.unshift([obj.class.respond_to?(method), obj.metaclass.respond_to?(method), NoMethodError]) end arr end end class Object include Debugs def metaclass class << self self end end end Wow this whole metaclass, class, object, module relationship is pretty mindbending... Cheers, -Adam