* object.c (rb_obj_cmp): defines Object#<=>. [ruby-core:24063]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25453 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2009-10-24 16:48:05 +00:00
parent 66ed25f633
commit 51f033f853
3 changed files with 15 additions and 1 deletions

View File

@ -1,3 +1,7 @@
Sat Oct 24 13:38:45 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (rb_obj_cmp): defines Object#<=>. [ruby-core:24063]
Sat Oct 24 00:36:47 2009 Tanaka Akira <akr@fsij.org>
* io.c (io_cntl): update max file descriptor by the result of

View File

@ -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

View File

@ -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);