Module: Comparable
Overview
Comparable
ISO 15.3.3
Instance Method Summary (collapse)
-
- (Object) <(other)
Return true if
self
is less thanother
. -
- (Object) <=(other)
Return true if
self
is less than or equal toother
. -
- (Object) ==(other)
Return true if
self
is equal toother
. -
- (Object) >(other)
Return true if
self
is greater thanother
. -
- (Object) >=(other)
Return true if
self
is greater than or equal toother
. -
- (Boolean) between?(min, max)
Return true if
self
is greater than or equal tomin
and less than or equal tomax
.
Instance Method Details
- (Object) <(other)
Return true if self
is less than other
. Otherwise
return false.
ISO 15.3.3.2.1
13 14 15 16 17 18 19 |
# File 'mrblib/compar.rb', line 13 def < other cmp = self <=> other if cmp.nil? raise ArgumentError, "comparison of #{self.class} with #{other.class} failed" end cmp < 0 end |
- (Object) <=(other)
Return true if self
is less than or equal to
other
. Otherwise return false.
ISO 15.3.3.2.2
27 28 29 30 31 32 33 |
# File 'mrblib/compar.rb', line 27 def <= other cmp = self <=> other if cmp.nil? raise ArgumentError, "comparison of #{self.class} with #{other.class} failed" end cmp <= 0 end |
- (Object) ==(other)
Return true if self
is equal to other
. Otherwise
return false.
ISO 15.3.3.2.3
41 42 43 44 |
# File 'mrblib/compar.rb', line 41 def == other cmp = self <=> other cmp == 0 end |
- (Object) >(other)
Return true if self
is greater than other
.
Otherwise return false.
ISO 15.3.3.2.4
52 53 54 55 56 57 58 |
# File 'mrblib/compar.rb', line 52 def > other cmp = self <=> other if cmp.nil? raise ArgumentError, "comparison of #{self.class} with #{other.class} failed" end cmp > 0 end |
- (Object) >=(other)
Return true if self
is greater than or equal to
other
. Otherwise return false.
ISO 15.3.3.2.5
66 67 68 69 70 71 72 |
# File 'mrblib/compar.rb', line 66 def >= other cmp = self <=> other if cmp.nil? raise ArgumentError, "comparison of #{self.class} with #{other.class} failed" end cmp >= 0 end |
- (Boolean) between?(min, max)
Return true if self
is greater than or equal to
min
and less than or equal to max
. Otherwise
return false.
ISO 15.3.3.2.6
81 82 83 |
# File 'mrblib/compar.rb', line 81 def between?(min, max) self >= min and self <= max end |