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

**URL:** <https://www.ruby-forum.com/t/is-there-interest-in-this-get-object-from-its-object-spec/88966>\
**Category:** Ruby\
**Created:** [March 15, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/is-there-interest-in-this-get-object-from-its-object-spec/88966 "2007-03-15T23:14:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rykkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@rykkers](https://www.ruby-forum.com/u/rykkers)\
**Post date:** [March 15, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/is-there-interest-in-this-get-object-from-its-object-spec/88966/1 "2007-03-15T23:14:50Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

IPMS/USA Region 12 Coordinator  
[http://ipmsr12.denhaven2.com/](http://ipmsr12.denhaven2.com/)

Visit the Project Mercury Wiki Site  
[http://www.mercuryspacecraft.com/](http://www.mercuryspacecraft.com/)
