[Bug:1.9] Time.now <=> SimpleDelegator.new(Time.now)

Time.now <=> SimpleDelegator.new(Time.now) e$B$,e(B nil e$B$K$J$k$N$Oe(B
SimpleDelegator.new(Time.now) <=> Time.now e$B$,$=$&$J$i$J$$$Ne(B
e$B$H0c$C$F$h$m$7$/$J$$$s$8$c$J$$$G$7$g$&$+!#e(B

% ./ruby -rdelegate -ve ’
t = Time.now
d = SimpleDelegator.new(Time.now)
p t <=> d
p d <=> t

ruby 1.9.0 (2008-06-09 revision 17043) [i686-linux]
/home/akr/ruby/yarvo0/lib/ruby/1.9.0/delegate.rb:225: warning: instance
variable @delegate_sd_obj not initialized
nil
1

e$B%o%J%Y$H?=$7$^$9!#e(B

2008/06/09 15:56 Tanaka A. [email protected]:

Time.now <=> SimpleDelegator.new(Time.now) e$B$,e(B nil e$B$K$J$k$N$Oe(B
SimpleDelegator.new(Time.now) <=> Time.now e$B$,$=$&$J$i$J$$$Ne(B
e$B$H0c$C$F$h$m$7$/$J$$$s$8$c$J$$$G$7$g$&$+!#e(B

e$B%Q%C%A$r=q$$$F$_$^$7$?$,e(B rb_funcall
e$B$,B?$/!“7k2L$,%3%9%H$K8+9g$C$F$$$J$$5$$,$7$^$9!#e(B
e$B$J$K$+NI$$J}K!$r$4B8CN$NJ}$O65$([email protected]$1$k$H$”$j$,$?$$$G$9!#e(B

Index: time.c

— time.c (revision 18196)
+++ time.c (working copy)
@@ -1087,7 +1087,16 @@
if (tobj1->ts.tv_sec > tobj2->ts.tv_sec) return INT2FIX(1);
return INT2FIX(-1);
}

  • else if (RTEST(rb_funcall(time2, rb_intern(“kind_of?”), 1,
    rb_cTime))) {

  • VALUE tmp = rb_funcall(time2, rb_intern("<=>"), 1, time1);

  • if (NIL_P(tmp)) return Qnil;

  • if (!FIXNUM_P(tmp)) {

  •  return rb_funcall(LONG2FIX(0), '-', 1, tmp);
    
  • }

  • return LONG2NUM(-FIX2LONG(tmp));

  • }

  • return Qnil;
    }

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:35830] Re: [Bug:1.9] Time.now <=>
SimpleDelegator.new(Time.now)”
on Tue, 12 Aug 2008 18:49:39 +0900, wanabe [email protected]
writes:

|2008/06/09 15:56 Tanaka A. [email protected]:
|> Time.now <=> SimpleDelegator.new(Time.now) e$B$,e(B nil e$B$K$J$k$N$Oe(B
|> SimpleDelegator.new(Time.now) <=> Time.now e$B$,$=$&$J$i$J$$$Ne(B
|> e$B$H0c$C$F$h$m$7$/$J$$$s$8$c$J$$$G$7$g$&$+!#e(B
|
|e$B%Q%C%A$r=q$$$F$_$^$7$?$,e(B rb_funcall e$B$,B?$/!“7k2L$,%3%9%H$K8+9g$C$F$$$J$$5$$,$7$^$9!#e(B
|e$B$J$K$+NI$$J}K!$r$4B8CN$NJ}$O65$([email protected]$1$k$H$”$j$,$?$$$G$9!#e(B

<=>e$B$,7?$,9g$o$J$$$He(Bnile$B$rJV$9$3$H$,4|BT$5$l$F$$$k$3$H$rMxMQ$7e(B
e$B$F0J2<$N$h$&$K$7$F$_$^$7$?!#e(B

— a/time.c
+++ b/time.c
@@ -1087,8 +1087,18 @@ time_cmp(VALUE time1, VALUE time2)
if (tobj1->ts.tv_sec > tobj2->ts.tv_sec) return INT2FIX(1);
return INT2FIX(-1);
}

  • else {
  • VALUE cmp;
  • int n;
  • cmp = rb_funcall(time2, rb_intern("<=>"), 1, time1);
  • if (NIL_P(cmp)) return Qnil;
  • return Qnil;
  • n = rb_cmpint(cmp, time1, time2);
  • if (n == 0) return INT2FIX(0);
  • if (n > 0) return INT2FIX(1);
  • return INT2FIX(-1);
  • }
    }

/*