diff --git a/ChangeLog b/ChangeLog index 6e829ade40..0d294d2d03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Oct 24 13:38:45 2009 Yukihiro Matsumoto + + * object.c (rb_obj_cmp): defines Object#<=>. [ruby-core:24063] + Sat Oct 24 00:36:47 2009 Tanaka Akira * io.c (io_cntl): update max file descriptor by the result of diff --git a/lib/delegate.rb b/lib/delegate.rb index 9ce3aee81e..77804e47ff 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -115,7 +115,7 @@ # implementation, see SimpleDelegator. # class Delegator - [:to_s,:inspect,:=~,:!~,:===].each do |m| + [:to_s,:inspect,:=~,:!~,:===,:<=>].each do |m| undef_method m end diff --git a/object.c b/object.c index 6e69343732..9f7537f12b 100644 --- a/object.c +++ b/object.c @@ -1119,6 +1119,15 @@ rb_obj_not_match(VALUE obj1, VALUE obj2) } +/* :nodoc: */ +static VALUE +rb_obj_cmp(VALUE obj1, VALUE obj2) +{ + if (obj1 == obj2 || rb_obj_equal(obj1, obj2)) + return INT2FIX(0); + return Qnil; +} + /*********************************************************************** * * Document-class: Module @@ -2555,6 +2564,7 @@ Init_Object(void) rb_define_method(rb_mKernel, "!~", rb_obj_not_match, 1); rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1); rb_define_method(rb_mKernel, "hash", rb_obj_hash, 0); + rb_define_method(rb_mKernel, "<=>", rb_obj_cmp, 1); rb_define_method(rb_mKernel, "class", rb_obj_class, 0); rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);