Project

General

Profile

Bug #14031

WeakRef example misleading and wrong

Added by marcandre (Marc-Andre Lafortune) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
trunk
[ruby-core:83366]

Description

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 WeakHash in
https://ruby-doc.org/stdlib-2.4.0/libdoc/weakref/rdoc/WeakRef.html

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 false.

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.

Associated revisions

Revision 013dcf08
Added by marcandre (Marc-Andre Lafortune) over 1 year ago

lib/weakref: Remove incorrect example [DOC] [Bug #14031]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60404
Added by marcandre (Marc-Andre Lafortune) over 1 year ago

lib/weakref: Remove incorrect example [DOC] [Bug #14031]

Revision 60404
Added by marcandre (Marc-Andre Lafortune) over 1 year ago

lib/weakref: Remove incorrect example [DOC] [Bug #14031]

Revision 60404
Added by marcandre (Marc-Andre Lafortune) over 1 year ago

lib/weakref: Remove incorrect example [DOC] [Bug #14031]

History

Updated by shevegen (Robert A. Heiler) over 1 year ago

Semi-off topic - a variable named "omg" is for the win ... ;)

#2

Updated by marcandre (Marc-Andre Lafortune) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r60404.


lib/weakref: Remove incorrect example [DOC] [Bug #14031]

Also available in: Atom PDF