On Mar 15, 2013 11:42 PM, "Love U Ruby" <lists / ruby-forum.com> wrote:
>
> Hi,
>
> I have some confusion with "ancestor" method.
>
> Can you help me out to clear the concept?
>
> class A
> end
>
> A.ancestors # => [A, Object, Kernel, BasicObject] <~~ Here why came? I
> actually expect the output as below one.
>
> A.class.ancestors # => [Class, Module, Object, Kernel, BasicObject]

Think of this:

a = A.new
a.class #=> A
a.class.ancestors #=> [A, Object, Kernel, BasicObject]
a.is_a? Object #=> true
a.is_a? Module #=> false

A.class #=> Class
A.class.ancestors #=> [Class, Module, Object, Kernel, BasicObject]
A.is_a? Object #=> true
A.is_a? Module #=> true

So x.ancestors means "list of classes and modules x extends/includes" and
y.class.ancestors means "list of classes and modules y.is_a? or
y.instance_of?"

This question should be in a separate thread.

Sent from my phone, so excuse the typos.