Project

General

Profile

Actions

Bug #431

closed

Time.now <=> SimpleDelegator.new(Time.now)

Added by matz (Yukihiro Matsumoto) over 15 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
Backport:
[ruby-dev:35838]

Description

=begin
まつもと ゆきひろです

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 writes:

|2008/06/09 15:56 Tanaka Akira :
|> Time.now <=> SimpleDelegator.new(Time.now) が nil になるのは
|> SimpleDelegator.new(Time.now) <=> Time.now がそうならないの
|> と違ってよろしくないんじゃないでしょうか。
|
|パッチを書いてみましたが rb_funcall が多く、結果がコストに見合っていない気がします。
|なにか良い方法をご存知の方は教えていただけるとありがたいです。

<=>が型が合わないとnilを返すことが期待されていることを利用し
て以下のようにしてみました。

--- 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);
  • }
    }

/*
=end


Related issues 1 (0 open1 closed)

Precedes Ruby master - Bug #123: Time.now <=> SimpleDelegator.new(Time.now)Closedmatz (Yukihiro Matsumoto)Actions
Actions #1

Updated by matz (Yukihiro Matsumoto) over 15 years ago

  • Status changed from Open to Feedback

=begin

=end

Actions #2

Updated by matz (Yukihiro Matsumoto) over 15 years ago

  • Status changed from Feedback to Closed

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0