WeakRef example misleading and wrong
I just noticed that the second part of the doc of
WeakRef is misleading and later plainly wrong.
I'm talking about the example with
The example shows
GC.start c['foo'] #=> nil c['baz'] #=> nil c['qux'] #=> nil
This is very misleading, since even before the GC that would be also the case, because
WeakHash didn't redefine the lookup, and that
WeakHash.new('foo').eql?('foo') is always
The doc goes on with:
"You can see the local variable
omg stayed, although its reference in our hash object was garbage collected, along with the rest of the keys and values."
That is wrong. The reference in our hash object was not garbage collected, since
omg held on to it. This can be proven with
c.values.last # => 'lol'.
My opinion is that fixing this example isn't worth it, and that even fixed it wouldn't add anything to the first simple example on WeakRef. In it's current form, it is worse dans not having it. Unless there are objections, I'll simply remove it.