On Wednesday, May 19, 2010 01:53:58 pm Robert Klemme wrote:
> 2010/5/19 David Masover <ninja / slaphack.com>:
> > On Wednesday, May 19, 2010 09:54:03 am Robert Klemme wrote:
> >> 2010/5/19 Walle Wallen <walle.sthlm / gmail.com>:
> >> > Quick question. Can I somehow retrieve the instance of the class Test
> >> > in which the variable con exists. As in the example below, can I
> >> > retrieve the instance of Test from the variable p?
> >> 
> >> There is no general mechanism that would allow to follow an object
> >> reference backwards.  If there was, that mechanism would yield
> >> multiple instances because a object can be referenced by any number of
> >> other objects.
> > 
> > Well, there's ObjectSpace. Probably not general (cross-interpreter), but
> > it does work if you actually need this functionality.
> 
> Even with ObjectSpace you cannot really travel a reference backwards.
> You're merely forced to look at all objects (of a kind) and figure
> whether any of them references (forward) the one whose parent you are
> looking for as your code nicely demonstrates.

I suppose. I still tend to think of things like this, because the Internet is 
actually eroding that kind of assumption. Once upon a time, I might have 
considered having another identity online, but occasionally linking back to my 
"real" identity. Basically, people who know me as SecretGuy could find out who 
I actually am, but not the other way around, with the assumption that friends 
and family from reality wouldn't be likely to stumble on SecretGuy.

But the idea of one-way links on the Web is just as absurd as the idea of one-
way links in SQL. The assumption that no one would ever look through the 
entire Internet for my alter-egos, or stumble on one by chance, is destroyed 
by the fact that Google already indexes the entire Internet, turning forward 
references into backward references.

Something similar could be done with ObjectSpace, but it'd be even more 
ridiculous:

Thread do
  loop do
    ObjectSpace.each_object(Test) do |t|
      con.instance_variable_set :@__test__, t
    end
    sleep 30
  end
end

def find_con con
  con.instance_variable_get :@__test__
end

I'll leave it as an exercise to the reader why that's so bad, and how it might 
be improved on.

But this can't be good for my sanity.

> > Just do what Robert Klein said.
> 
> Erm, who?

Whoops... Actually, what is the etiquette on a forum like this? Should I just 
say "Robert"?