Commit abb4e583 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #198 from bovi/add-compar-doc

Add documentation to Comparable
parents f6d539ea c1faad90
##
# Comparable
#
# ISO 15.3.3
module Comparable module Comparable
# 15.3.3.2.1
##
# Return true if +self+ is less
# than +other+. Otherwise return
# false.
#
# ISO 15.3.3.2.1
def < other def < other
cmp = self <=> other cmp = self <=> other
if cmp.nil? if cmp.nil?
...@@ -11,7 +21,12 @@ module Comparable ...@@ -11,7 +21,12 @@ module Comparable
end end
end end
# 15.3.3.2.2 ##
# Return true if +self+ is less
# than or equal to +other+.
# Otherwise return false.
#
# ISO 15.3.3.2.2
def <= other def <= other
cmp = self <=> other cmp = self <=> other
if cmp.nil? if cmp.nil?
...@@ -23,7 +38,12 @@ module Comparable ...@@ -23,7 +38,12 @@ module Comparable
end end
end end
# 15.3.3.2.3 ##
# Return true if +self+ is equal
# to +other+. Otherwise return
# false.
#
# ISO 15.3.3.2.3
def == other def == other
cmp = self <=> other cmp = self <=> other
if cmp == 0 if cmp == 0
...@@ -33,7 +53,12 @@ module Comparable ...@@ -33,7 +53,12 @@ module Comparable
end end
end end
# 15.3.3.2.4 ##
# Return true if +self+ is greater
# than +other+. Otherwise return
# false.
#
# ISO 15.3.3.2.4
def > other def > other
cmp = self <=> other cmp = self <=> other
if cmp.nil? if cmp.nil?
...@@ -45,9 +70,14 @@ module Comparable ...@@ -45,9 +70,14 @@ module Comparable
end end
end end
# 15.3.3.2.5 ##
# Return true if +self+ is greater
# than or equal to +other+.
# Otherwise return false.
#
# ISO 15.3.3.2.5
def >= other def >= other
cmp = self <=> other cmp = self <=> other
if cmp.nil? if cmp.nil?
false false
elsif cmp >= 0 elsif cmp >= 0
...@@ -57,8 +87,14 @@ module Comparable ...@@ -57,8 +87,14 @@ module Comparable
end end
end end
# 15.3.3.2.6 ##
def 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
def between?(min, max)
if self < min or self > max if self < min or self > max
false false
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment