summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-13 09:04:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-13 09:04:32 +0000
commit056f219ecaa8daa50a77d28bed49fb5a4bf75928 (patch)
tree331b0dad1cf037e44c5fd9841d02145a86d3494c /lib
parent107ead2b961452a8df2d0b63eda34b45d9b4ef75 (diff)
1.1b9_02
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/weakref.rb29
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/weakref.rb b/lib/weakref.rb
index 18d3bbc9a3..6a6dcec5a1 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -31,26 +31,27 @@ class WeakRef<Delegator
def initialize(orig)
super
- @id = orig.id
+ @__id = orig.id
ObjectSpace.call_finalizer orig
- ID_MAP[@id] = self.id
- ID_REV_MAP[self.id] = @id
+ ObjectSpace.call_finalizer self
+ ID_MAP[@__id] = self.id
+ ID_REV_MAP[self.id] = @__id
end
def __getobj__
- unless ID_MAP[@id]
+ unless ID_MAP[@__id]
$@ = caller(1)
$! = RefError.new("Illegal Reference - probably recycled")
raise
end
- ObjectSpace.id2ref(@id)
+ ObjectSpace._id2ref(@__id)
# ObjectSpace.each_object do |obj|
-# return obj if obj.id == @id
+# return obj if obj.id == @__id
# end
end
def weakref_alive?
- if ID_MAP[@id]
+ if ID_MAP[@__id]
true
else
false
@@ -62,9 +63,11 @@ class WeakRef<Delegator
end
end
-foo = Object.new
-p foo.hash
-foo = WeakRef.new(foo)
-p foo.hash
-ObjectSpace.garbage_collect
-p foo.hash
+if __FILE__ == $0
+ foo = Object.new
+ p foo.hash
+ foo = WeakRef.new(foo)
+ p foo.hash
+ ObjectSpace.garbage_collect
+ p foo.hash
+end