From: Matthew Kerwin Date: 2013-03-16T05:35:04+09:00 Subject: Re: Confusion with Strings --bcaec554e1066a548c04d7fc8e81 Content-Type: text/plain; charset=ISO-8859-1 On Mar 15, 2013 11:42 PM, "Love U Ruby" 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. --bcaec554e1066a548c04d7fc8e81 Content-Type: text/html; charset=ISO-8859-1

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.

--bcaec554e1066a548c04d7fc8e81--