On 2/4/06, Robert Klemme <shortcutter / googlemail.com> wrote:
> > I now see that I also get the problem with my ruby 1.6 _if_ I run the
> > test program within irb; without irb, it runs without problems.
>
> I would not count on IRB in such circumstances - especially if local
> variables are involved. IRB does certain things differently there. Did
> you only test in IRB or also in a Ruby script?

It happens running it with plain ruby (no irb) on my ruby 1.8 (and
1.9). I only mentioned it because irb does seem to be required to
create the problem on my ruby 1.6. Irb is not the problem; it doesn't
treat local variables that differently.

> Not so fast. This error you are seeing is absolutely expected:
> i.__getobj__ returns the original instance. If that is not an object
> id (which it isn't in your case) it's not a legal argument for
> ObjectSpace._id2ref().
>
> You probably wanted o2=i.__getobj__

Uh-oh. You're right. Too much monkey code and hack, not enough look and think.

(After hurriedly fixing my test...) Ok, so if I _correctly_ use
WeakRefs, there is no problem. That is interesting, and I'd sure like
to know why, because it's not obvious to me. I'm going to investigate
this deeper, and see if I isolate the difference that lets WeakRef
work.

> Since you keep a reference to o all the time in the block,
> ObjectSpace._id2ref must always return the same instance. *If* you
> actually see the error you claimed you saw initially then there's
> something seriously broken.  At the moment I rather suspect it's some
> other issue (such as testing in IRB).  I'd also try to use brackets
> around the equality test - just to be sure that precedence doesn't
> come into play.

I'm pretty sure about the precedence of or, but just in case, I tried
it with more parens. It's still broken.