mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Refactoring Comparable
This commit is contained in:
+6
-26
@@ -14,11 +14,8 @@ module Comparable
|
|||||||
cmp = self <=> other
|
cmp = self <=> other
|
||||||
if cmp.nil?
|
if cmp.nil?
|
||||||
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
||||||
elsif cmp < 0
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
cmp < 0
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -31,11 +28,8 @@ module Comparable
|
|||||||
cmp = self <=> other
|
cmp = self <=> other
|
||||||
if cmp.nil?
|
if cmp.nil?
|
||||||
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
||||||
elsif cmp <= 0
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
cmp <= 0
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -46,11 +40,7 @@ module Comparable
|
|||||||
# ISO 15.3.3.2.3
|
# ISO 15.3.3.2.3
|
||||||
def == other
|
def == other
|
||||||
cmp = self <=> other
|
cmp = self <=> other
|
||||||
if cmp == 0
|
cmp == 0
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -63,11 +53,8 @@ module Comparable
|
|||||||
cmp = self <=> other
|
cmp = self <=> other
|
||||||
if cmp.nil?
|
if cmp.nil?
|
||||||
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
||||||
elsif cmp > 0
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
cmp > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -80,11 +67,8 @@ module Comparable
|
|||||||
cmp = self <=> other
|
cmp = self <=> other
|
||||||
if cmp.nil?
|
if cmp.nil?
|
||||||
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
||||||
elsif cmp >= 0
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
cmp >= 0
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -95,10 +79,6 @@ module Comparable
|
|||||||
#
|
#
|
||||||
# ISO 15.3.3.2.6
|
# ISO 15.3.3.2.6
|
||||||
def between?(min, max)
|
def between?(min, max)
|
||||||
if self < min or self > max
|
self >= min and self <= max
|
||||||
false
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user