On Apr 2, 2004, at 11:43 AM, David King Landrith wrote:

>
> On Apr 2, 2004, at 11:31 AM, ts wrote:
>
>>>>>>> "D" == David King Landrith <dlandrith / mac.com> writes:
>>
>> D> Is there any way to access the name of a given variable instance 
>> from
>> D> within it?  In other words, for any object x, is there C function 
>> to
>> D> which I can pass self to determine that the program calls it 'x'?
>>
>>  Well, with this
>>
>>   a = b = 12
>
>>  which is the name associated with the object 12 ?
>
> From what I understand, since 12 is a FixNum, a and b end up being 
> separate FixNum objects with their own separate values of 12.  But 
> this strikes me as beside the point.

I think this is what ts is pointing out:

   # set a, b and c; set a's @foo instance variable to 42
   a = b = 23                 #=> 23
   a.instance_eval{@foo=42}   #=> 42
   c = 23                     #=> 23

   # show everyone's @foo
   [ a.instance_eval{@foo},
     b.instance_eval{@foo},
     c.instance_eval{@foo},
     23.instance_eval{@foo}]  #=> [42, 42, 42, 42]

   # show everyone's id
   [a.id, b.id, c.id, 23.id]  #=> [47, 47, 47, 47]

All instances of 23 are exactly the same object. No difference 
whatsoever. the variable name is like a nickname (thanks Why :), it's 
just one of many pointers to the object. I really don't think that 
there is any way to get the name assigned to that pointer, especially 
since the number of names assigned to that one object can be anywhere 
from 0 to infinity :) (well, infinite for practical purposes anyway...)

I looked around though, at Symbols.all_symbols, 
ObjectSpace.each_object, and I couldn't find any way to tie them 
together... perhaps there is a way, but I'm not sure that you will be 
getting the right symbol for the context you are in even if you do...

--Mark