PartialComparable
module PartialComparable(T)
Overview
The PartialComparable
mixin is used by classes whose objects may be partially ordered.
Including types must provide an <=>
method, which compares the receiver against another object, returning -1
, 0
, +1
or nil
depending on whether the receiver is less than, equal to, greater than the other object, or no order can be established.
PartialComparable
uses <=>
to implement the conventional comparison operators (#<
, #<=
, #==
, #>=
, and #>
).
Defined in:
partial_comparable.crInstance Method Summary
- #<(other : T)
Compares this object to other based on the receiver’s
<=>
method, returningtrue
if it returns-1
. - #<=(other : T)
Compares this object to other based on the receiver’s
<=>
method, returningtrue
if it returns-1
or0
. - #==(other : T)
Compares this object to other based on the receiver’s
<=>
method, returningtrue
if it returns0
. - #>(other : T)
Compares this object to other based on the receiver’s
<=>
method, returningtrue
if it returns1
. - #>=(other : T)
Compares this object to other based on the receiver’s
<=>
method, returningtrue
if it returns1
or0
. - #compare_with(other : T, &block)
Instance Method Detail
def <(other : T)Source
Compares this object to other based on the receiver’s <=>
method, returning true
if it returns -1
.
def <=(other : T)Source
Compares this object to other based on the receiver’s <=>
method, returning true
if it returns -1
or 0
.
def ==(other : T)Source
Compares this object to other based on the receiver’s <=>
method, returning true
if it returns 0
. Also returns true
if this and other are the same object.
def >(other : T)Source
Compares this object to other based on the receiver’s <=>
method, returning true
if it returns 1
.
def >=(other : T)Source
Compares this object to other based on the receiver’s <=>
method, returning true
if it returns 1
or 0
.
def compare_with(other : T, &block)Source
© 2012–2017 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.22.0/PartialComparable.html