From 1dc46d8782dd34738ed2970b0b68ce17739bd076 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 24 Oct 2009 16:48:05 +0000 Subject: * object.c (rb_obj_cmp): defines Object#<=>. [ruby-core:24063] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'object.c') diff --git a/object.c b/object.c index 6e6934373..9f7537f12 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); -- cgit