Project

General

Profile

Actions

Bug #5012

closed

Timeオブジェクト間で特異オブジェクトが共有される

Added by ktsj (Kazuki Tsujimoto) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3dev (2011-07-10 trunk 32482) [x86_64-linux]
Backport:
[ruby-dev:44071]

Description

=begin
辻本です。

Time#getlocalなどによって返されるTimeオブジェクトが、
レシーバと特異オブジェクトを共有してしまっています。

t0 = Time.now
class <<t0; end

t1 = t0.getlocal

def t0.m
0
end

p t0.m # => 0
p t1.m # => 0

以下のパッチでどうでしょうか。

diff --git a/time.c b/time.c
index 5dbf9b2..eb49ef2 100644
--- a/time.c
+++ b/time.c
@@ -3426,7 +3426,7 @@ time_init_copy(VALUE copy, VALUE time)
static VALUE
time_dup(VALUE time)
{

  • VALUE dup = time_s_alloc(CLASS_OF(time));
  • VALUE dup = time_s_alloc(rb_obj_class(time));
    time_init_copy(dup, time);
    return dup;
    }
    =end
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0