1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1998-06-08 01:40:08 +00:00
parent 5196e8609b
commit 7acc47fe82
4 changed files with 63 additions and 49 deletions

View file

@ -41,14 +41,9 @@ class WeakRef<Delegator
def __getobj__
unless ID_MAP[@__id]
$@ = caller(1)
$! = RefError.new("Illegal Reference - probably recycled")
raise
raise RefError, "Illegal Reference - probably recycled", caller(2)
end
ObjectSpace._id2ref(@__id)
# ObjectSpace.each_object do |obj|
# return obj if obj.id == @__id
# end
end
def weakref_alive?
@ -66,9 +61,9 @@ end
if __FILE__ == $0
foo = Object.new
p foo.hash
p foo.hash # original's hash value
foo = WeakRef.new(foo)
p foo.hash
p foo.hash # should be same hash value
ObjectSpace.garbage_collect
p foo.hash
p foo.hash # should raise exception (recycled)
end