From: Marc-Andre Lafortune Date: 2009-10-13T11:40:44+09:00 Subject: [ruby-core:26067] [Feature #1697] Object#<=> 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 obj is smaller than other, + * 0 if obj is the same as other, and +1 if obj is + * greater than other. Returns nil if obj + * can not be compared with other. + * 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