[#25936] [Bug:1.9] [rubygems] $LOAD_PATH includes bin directory — Nobuyoshi Nakada <nobu@...>

Hi,

10 messages 2009/10/05

[#25943] Disabling tainting — Tony Arcieri <tony@...>

Would it make sense to have a flag passed to the interpreter on startup that

16 messages 2009/10/05

[#26028] [Bug #2189] Math.atanh(1) & Math.atanh(-1) should not raise an error — Marc-Andre Lafortune <redmine@...>

Bug #2189: Math.atanh(1) & Math.atanh(-1) should not raise an error

14 messages 2009/10/10

[#26222] [Bug #2250] IO::for_fd() objects' finalization dangerously closes underlying fds — Mike Pomraning <redmine@...>

Bug #2250: IO::for_fd() objects' finalization dangerously closes underlying fds

11 messages 2009/10/22

[#26244] [Bug #2258] Kernel#require inside rb_require() inside rb_protect() inside SysV context fails — Suraj Kurapati <redmine@...>

Bug #2258: Kernel#require inside rb_require() inside rb_protect() inside SysV context fails

24 messages 2009/10/22

[#26361] [Feature #2294] [PATCH] ruby_bind_stack() to embed Ruby in coroutine — Suraj Kurapati <redmine@...>

Feature #2294: [PATCH] ruby_bind_stack() to embed Ruby in coroutine

42 messages 2009/10/27

[#26371] [Bug #2295] segmentation faults — tomer doron <redmine@...>

Bug #2295: segmentation faults

16 messages 2009/10/27

[ruby-core:26067] [Feature #1697] Object#<=>

From: Marc-Andre Lafortune <redmine@...>
Date: 2009-10-13 02:40:44 UTC
List: ruby-core #26067
Issue #1697 has been updated by Marc-Andre Lafortune.


I would modify slightly Nobu's patch to return 0 if the two compared objects are one and the same. I also think it is probably a better choice to return nil instead of raising an error.

With this patch in, running 'make test' doesn't generate any error. 'make test-all' generates two, on for rake because Rake::FileList has a weak way to find which methods are proper to Array, and another error because of Delegator, which doesn't inherit from BasicObject (see issue 1333) and doesn't list :<=> in its list of methods to undefine. So both of these are trivially fixed.

Although I really would like an implementation of a good double dispatch scheme, I'll leave that discussion for another time.


diff --git a/object.c b/object.c
index e81007b..fdf1ee6 100644
--- a/object.c
+++ b/object.c
@@ -1115,13 +1115,23 @@ rb_obj_not_match(VALUE obj1, VALUE obj2)
     return RTEST(result) ? Qfalse : Qtrue;
 }
 
-/* :nodoc: */
+/*
+ *  call-seq:
+ *     obj <=> other       => -1, 0, 1 or nil
+ *
+ *  Comparison---Returns -1 if <i>obj</i> is smaller than <i>other</i>,
+ *  0 if <i>obj</i> is the same as <i>other</i>, and +1 if <i>obj</i> is
+ *  greater than <i>other</i>. Returns <code>nil</code> if <i>obj</i>
+ *  can not be compared with <i>other</i>.
+ *  Typically, this method is overridden in descendent
+ *  classes to provide class-specific meaning.
+ */
+
 static VALUE
 rb_obj_cmp(VALUE obj, VALUE arg)
 {
-    if (!rb_respond_to(arg, id_cmp)) {
-       rb_notimplement();
-    }
+    if (obj == arg)
+       return INT2FIX(0);
     return Qnil;
 }

----------------------------------------
http://redmine.ruby-lang.org/issues/show/1697

----------------------------------------
http://redmine.ruby-lang.org

In This Thread