On Sep 18, 2008, at 8:07 AM, Paul Brannan wrote:

> On Thu, Sep 18, 2008 at 04:43:40AM +0900, ara.t.howard wrote:
>> it might not be a class... but will this work?
>
> It would, except that calling #singleton_class isn't the only way to  
> get
> a singleton class. :(

yup - i was afraid you'd say that...


>
>
>>    unless sc.respond_to?(:parent)
>>      parent_id = self.object_id #Module === self ? self : self.class
>>      sc.instance_eval "def parent()  
>> ObjectSpace._id2ref(#{ parent_id })
>> end"
>>    end
>
> Does doing this allow a class to be garbage-collected but allow its
> singleton class to stick around?
>

yes.  you don't have to worry about the object being stale when this  
is called since the singleton class if owned by the object it's  
looking up by id

> Probably better to use define_method with a block in this case.
>

i was worried about the gc. also you use define_method you have to get  
into the singleton class of a singleton class - which starts to get  
yucky.  'def' works at the instance scope so my approach seemed safer  
and simpler.  but i think define_method could be made to work...

> Paul
>
>

cheers.

a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama