1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* numeric.c (fix_equal, fix_cmp, fix_gt, fix_ge, fix_lt, fix_le):

reduce coercing when a method knows about a operand type.
  [ruby-dev:26789]

* lib/delegate.rb: simplifies Delegator classes; SimpleDelegator
  now uses method_missing for all methods.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2005-08-12 07:17:36 +00:00
parent d3de1ac85b
commit ec14c2c9b9
3 changed files with 53 additions and 51 deletions

View file

@ -18,7 +18,8 @@ class WeakRef<Delegator
@@id_map = {} # obj -> [ref,...]
@@id_rev_map = {} # ref -> obj
@@final = lambda{|id|
@@final = lambda {|id|
printf "final: %p\n", id
__old_status = Thread.critical
Thread.critical = true
begin
@ -42,6 +43,7 @@ class WeakRef<Delegator
def initialize(orig)
@__id = orig.object_id
printf "orig: %p\n", @__id
ObjectSpace.define_finalizer orig, @@final
ObjectSpace.define_finalizer self, @@final
__old_status = Thread.critical
@ -53,7 +55,7 @@ class WeakRef<Delegator
end
@@id_map[@__id].push self.object_id
@@id_rev_map[self.object_id] = @__id
super
super
end
def __getobj__
@ -66,6 +68,8 @@ class WeakRef<Delegator
Kernel::raise RefError, "Illegal Reference - probably recycled", Kernel::caller(2)
end
end
def __setobj__(obj)
end
def weakref_alive?
@@id_rev_map[self.object_id] == @__id
@ -73,11 +77,12 @@ class WeakRef<Delegator
end
if __FILE__ == $0
require 'thread'
# require 'thread'
foo = Object.new
p foo.to_s # original's class
foo = WeakRef.new(foo)
p foo.to_s # should be same class
ObjectSpace.garbage_collect
ObjectSpace.garbage_collect
p foo.to_s # should raise exception (recycled)
end