summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-06-08 01:40:08 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-06-08 01:40:08 +0000
commit7acc47fe82fd49cc5ac5d63ec67a2be92ad56d3c (patch)
tree5b5183b1d17756d2fb304957e82aea15dba52a8d /lib
parent5196e8609ba576021305710610b071d31777e798 (diff)
regex.c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/delegate.rb18
-rw-r--r--lib/weakref.rb13
2 files changed, 20 insertions, 11 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb
index bc6f876..7889c82 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -21,7 +21,17 @@ class Delegator
preserved -= ["__getobj__","to_s","nil?","to_a","hash","dup","==","=~"]
for method in obj.methods
next if preserved.include? method
- eval "def self.#{method}(*args,&block); __getobj__.__send__(:#{method}, *args,&block); end"
+ eval <<EOS
+def self.#{method}(*args, &block)
+ begin
+ __getobj__.__send__(:#{method}, *args, &block)
+ rescue Exception
+ n = if /:in `__getobj__'$/ =~ $@[0] then 1 else 2 end #`
+ $@[1,n] = nil
+ raise
+ end
+end
+EOS
end
end
@@ -53,6 +63,10 @@ SimpleDelegater = SimpleDelegator
if __FILE__ == $0
foo = Object.new
+ def foo.test
+ raise 'this is OK'
+ end
foo2 = SimpleDelegator.new(foo)
- p foo.hash == foo2.hash # => true
+ p foo.hash == foo2.hash # => true
+ foo.test # raise error!
end
diff --git a/lib/weakref.rb b/lib/weakref.rb
index 6ef4b42..539bb93 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -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