Project

General

Profile

Actions

Bug #123

closed

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

Added by Anonymous almost 16 years ago. Updated almost 13 years ago.

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

Description

=begin
Time.now <=> SimpleDelegator.new(Time.now) が nil になるのは
SimpleDelegator.new(Time.now) <=> Time.now がそうならないの
と違ってよろしくないんじゃないでしょうか。

% ./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

[田中 哲][たなか あきら][Tanaka Akira]
=end


Related issues 1 (0 open1 closed)

Follows Ruby master - Bug #431: Time.now <=> SimpleDelegator.new(Time.now)ClosedActions
Actions #1

Updated by matz (Yukihiro Matsumoto) almost 16 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

=begin

=end

Actions #2

Updated by matz (Yukihiro Matsumoto) over 15 years ago

  • Status changed from Open to Closed

=begin

=end

Actions #3

Updated by wanabe (_ wanabe) over 15 years ago

=begin
ワナベと申します。

2008/06/09 15:56 Tanaka Akira :

Time.now <=> SimpleDelegator.new(Time.now) が nil になるのは
SimpleDelegator.new(Time.now) <=> Time.now がそうならないの
と違ってよろしくないんじゃないでしょうか。

パッチを書いてみましたが rb_funcall が多く、結果がコストに見合っていない気がします。
なにか良い方法をご存知の方は教えていただけるとありがたいです。

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

--
ワナベ

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0