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

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 [email protected] 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/

IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/

Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/