, , , .
Spaceship-Operator (<=>) Comparable.
class Fruit
attr_accessor :name, :color
def <=>(other)
[self.name.downcase, self.color] <=> [other.name.downcase, other.color]
end
include Comparable
end
:
list_of_fruits.sort
(==, <, >) , , if (apple < banana) (. )
<=> Is returned for a refund -1if selfless other, +1if otherless, and 0if the two objects are equal.
source
share