From: Matthew Kerwin Date: 2013-03-16T06:25:34+09:00 Subject: Re: Confusion with Strings --bcaec554d43442101604d7fd4700 Content-Type: text/plain; charset=ISO-8859-1 On Mar 16, 2013 7:10 AM, "Love U Ruby" wrote: > > Love U Ruby wrote in post #1101762: > > Hi, > > > > > class A > > end > > > > A.ancestors # => [A, Object, Kernel, BasicObject] > > My question is - how does `A` come in the output of `A.ancestors` ? > Based on my previous samples: a.is_a? A #=> true A.is_a? A #=> false The first is true because A.ancestors.include? A You can also do this: def decl cls cls.ancestors.reverse.inject do |p,c| puts "class #{c} < #{p}" puts 'end' end end decl A Note: I've ignored included modules. Sent from my phone, so excuse the typos. --bcaec554d43442101604d7fd4700 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Mar 16, 2013 7:10 AM, "Love U Ruby" <lists@ruby-forum.com> wrote:
>
> Love U Ruby wrote in post #1101762:
> > Hi,
> >
>
> > class A
> > end
> >
> > A.ancestors # =3D> [A, Object, Kernel, BasicObject]
>
> My question is - how does `A` come in the output of `A.ancestors` ? >

Based on my previous samples:

a.is_a? A #=3D> true
A.is_a? A #=3D> false

The first is true because A.ancestors.include? A

You can also do this:

def decl cls
=A0 cls.ancestors.reverse.inject do |p,c|
=A0=A0=A0 puts "class #{c} < #{p}"
=A0=A0=A0 puts 'end'
=A0 end
end
decl A

Note: I've ignored included modules.

Sent from my phone, so excuse the typos.

--bcaec554d43442101604d7fd4700--