instance method
Object#<=>
(untyped other) -> 0?
self <=> other → 0 or nil
object.c
View on GitHub ↗
static VALUE
rb_obj_cmp(VALUE obj1, VALUE obj2)
{
if (rb_equal(obj1, obj2))
return INT2FIX(0);
return Qnil;
}
Compares self and other.
Returns:
-
0, ifselfandotherare the same object, or ifself == other. -
nil, otherwise.
Examples:
Example
o = Object.new o <=> o # => 0 o <=> o.dup # => nil
A class that includes module Comparable should override this method by defining an instance method that:
-
Take one argument,
other. -
Returns:
-
-1, ifselfis less thanother. -
0, ifselfis equal toother. -
1, ifselfis greater thanother. -
nil, if the two values are incommensurate.
-