From: "David A. Black" Date: 2004-03-09T01:53:52+09:00 Subject: Re: proposal: class< [Simon Strandgaard , 2004-03-08 16.19 CET] > > On Tue, 09 Mar 2004 00:02:13 +0900, Carlos wrote: > > [snip] > > > Maybe you should ask for a method #singleton for singleton classes, > > > that returns the object... ;) > > > > I tried poking around with 'singleton'.. but no luck. > > Please give me some more hints. > > No... it doesn't exist (as I know), but if it existed, you could > do what you are trying to do with > > class << obj > def init > ... > end > > singleton.init > end > > This is why I said that maybe you should ask for it (to Matz). Sorry > for false expectations... Here's a brute-force but perhaps useable implementation: class Class def single_instance ObjectSpace.each_object do |obj| c = (class << obj; self; end) return obj if c == self end end end p (class << "hello"; self; end).single_instance # "hello" David -- David A. Black dblack@wobblini.net