class Class
def mixin_ancestors(include_ancestors=true)
ancestors.take_while {|a| include_ancestors || a != superclass }.
select {|ancestor| ancestor.instance_of?(Module) }
end
end
class MyTestClass
end
Took the above code from How do you list included Modules in a Ruby Class?
I have following questions.
1) By saying 'def mixin_ancestors' as in the above code we are defining an instance method. But doing 'a = MyTestClass.new ; a.mixin_ancestors' says undefined method mixin_ancestors.
2) So I did ‘MyTestClass. mixin_ancestors’. It gave me a list .
3) I think ‘ancestors’ is a method. In which context does the ‘ancestors’ method runs. To find that I did ‘method(ancestors).owner’ but got error- method: [MyTestClass, Object, Kernel, BasicObject] is not a symbol (TypeError).
Got this trick from my own previous question Determine the class to which a method belongs in rails
4) Like third point on which context does superclass
method in the above code runs.
Thanks for the helps