```On Sep 13, 5:21=A0am, Sebastian Hungerecker <sep... / googlemail.com>
wrote:
> RichardOnRails wrote:
> > def parents(obj)
> > =A0 ( (obj.superclass ? parents(obj.superclass) : []) << obj). reverse
> > end
> > [...]
> > parents(Class).inspect =A0=3D> =A0[Class, Object, Module]
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Expected: =A0[Class, Module, Obj=
ect]
>
> Ok, here's what happens:
> parents(Class) =A0=3D (parents(Module) << Class).reverse
> parents(Module) =3D (parents(Object) << Module).reverse
> parents(Object) =3D [Object]
> parents(Module) =3D ([Object] << Module).reverse
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D [Module, Object]
> parents(Class) =A0=3D ([Module, Object] << Class).reverse
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D [Module, Object, Class].reverse
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D [Class, Object, Module]
>
> Anyway, do you know that you can get what you want just by calling
> TheClass.ancestors? Well, not quite as that also includes included
> modules, but TheClass.ancestors.grep(Class) would give you exactly
> the results you expected from your method.
>
> HTH,
> Sebastian
> --
> NP: Obituary - I'm in Pain
> Jabber: sep... / jabber.org
> ICQ: 205544826

Thanks, Sebastian!

I stupidly failed to recognize that "reverse" would affect each
iteration of the recursive routine, rather than merely to last
iteration as I intended.

I removed the interior "reverse" and the world is beautiful again, to
wit:

parents(Class).reverse.inspect
=3D> [Class, Module, Object]

> TheClass.ancestors?

I did know about that, but thanks for asking.  I wanted to write my
own trace routine so that I have my own insight into metaprogramming
techniques and the structure of Ruby.

Best wishes,
Richard

```