I believe you are looking for this:
class Class
def instance_methods_within(klass)
return self.instance_methods if klass == Object
methods = []
this = self
while this != nil
methods << this.instance_methods(false)
break if this == klass
this = this.superclass
end
return methods.flatten
end
end
class C; def c; end end
class B < C; def b; end end
class D < B; def d; end end
class A < D; def a; end end
A.instance_methods_within(Object)
A.instance_methods_within(C)
A.instance_methods_within(B)
A.instance_methods_within(D)
A.instance_methods_within(A)
Object, Object.instance_methods(false) [], , , . , instance_methods_within Class.