Jeff Patterson wrote:
> Thanks for the response. It seems to me that both of these issue could 
> be covered by simply returning an array of the symbol names which point 
> to a object or [] if an object has no name associated with it.

Potentially.  You could fudge it with something like (in Object):

def get_variable_names context, locals, instances
  names = []
  (locals + instances + global_variables).each do |var_name|
    if value = eval(var_name, context)
      names << var_name if value.object_id.eql?(object_id)
    end
  end
  names
end

and use it like:

foo.get_variable_names binding, local_variables, instance_variables

You need to pass in local and instance variable names because the 
context of the method call is different to the context of the caller and 
the caller's binding is needed to evaluate these.  There may be a way of 
getting the callers context which would give you these, but I don't know 
how offhand.

This is not a clean solution, and if Ruby doesn't give you the caller's 
context then the only other solution I can see is to carry the 
information around with the object.

-- 
Posted via http://www.ruby-forum.com/.