Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move body of Comparison from compar.c to compar.rb
- Loading branch information
Showing
2 changed files
with
64 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,68 @@ | ||
### move to compar.c | ||
# module Comparable | ||
# def == other | ||
# cmp = self <=> other | ||
# if cmp == 0 | ||
# true | ||
# else | ||
# false | ||
# end | ||
# end | ||
module Comparable | ||
# 15.3.3.2.1 | ||
def < other | ||
cmp = self <=> other | ||
if cmp.nil? | ||
false | ||
elsif cmp < 0 | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
# def < other | ||
# cmp = self <=> other | ||
# if cmp.nil? | ||
# false | ||
# elsif cmp < 0 | ||
# true | ||
# else | ||
# false | ||
# end | ||
# end | ||
# 15.3.3.2.2 | ||
def <= other | ||
cmp = self <=> other | ||
if cmp.nil? | ||
false | ||
elsif cmp <= 0 | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
# def <= other | ||
# cmp = self <=> other | ||
# if cmp.nil? | ||
# false | ||
# elsif cmp <= 0 | ||
# true | ||
# else | ||
# false | ||
# end | ||
# end | ||
# 15.3.3.2.3 | ||
def == other | ||
cmp = self <=> other | ||
if cmp == 0 | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
# def > other | ||
# cmp = self <=> other | ||
# if cmp.nil? | ||
# false | ||
# elsif cmp > 0 | ||
# true | ||
# else | ||
# false | ||
# end | ||
# end | ||
# 15.3.3.2.4 | ||
def > other | ||
cmp = self <=> other | ||
if cmp.nil? | ||
false | ||
elsif cmp > 0 | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
# def >= other | ||
# cmp = self <=> other | ||
# if cmp.nil? | ||
# false | ||
# elsif cmp >= 0 | ||
# true | ||
# else | ||
# false | ||
# end | ||
# end | ||
# 15.3.3.2.5 | ||
def >= other | ||
cmp = self <=> other | ||
if cmp.nil? | ||
false | ||
elsif cmp >= 0 | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
# def between?(min,max) | ||
# if self < min or self > max | ||
# false | ||
# else | ||
# true | ||
# end | ||
# end | ||
# end | ||
# 15.3.3.2.6 | ||
def between?(min,max) | ||
if self < min or self > max | ||
false | ||
else | ||
true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters