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.
Whoops... Actually, what is the etiquette on a forum like this? Should I just
say "Robert"?