Forum: Ruby Is there interest in this? : get object from its object-spec

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2007-03-15 23:14
(Received via mailing list)
The following is the culmination of a discussion on ruby-talk from a
few days ago.

Someone asked if there was a way to find the instance of a singleton
class if you only had the class.  After positing a solution using
ObjectSpace.each_object, I then wrote a small extension to get it via
the hidden __attached__ instance variable.

I was then asked to submit it to ruby-core, although I'm not sure
whether it's a problem which needs to be addressed in the core.

But just in case here's the discussion.  If there's interest, I could
come up with a patch for 1.8.5, 1.8.6, and maybe 1.9.

On 3/13/07, Trans <> wrote:
> > rick@frodo:/public/rubyscripts/getsinginst$ cat get_sing_inst.c
> >
> > sc = class << h
> >     ObjectSpace.each_object(sc) do |obj|
> >       end
> >
> >   end
> T.

Rick DeNatale

My blog on Ruby

IPMS/USA Region 12 Coordinator

Visit the Project Mercury Wiki Site
This topic is locked and can not be replied to.