Last change
on this file was 321, checked in by coas-nagasima, 7 years ago |
文字コードを設定
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-ruby;charset=UTF-8
|
File size:
1.5 KB
|
Line | |
---|
1 | ##
|
---|
2 | # Comparable
|
---|
3 | #
|
---|
4 | # ISO 15.3.3
|
---|
5 | module Comparable
|
---|
6 |
|
---|
7 | ##
|
---|
8 | # Return true if +self+ is less
|
---|
9 | # than +other+. Otherwise return
|
---|
10 | # false.
|
---|
11 | #
|
---|
12 | # ISO 15.3.3.2.1
|
---|
13 | def < other
|
---|
14 | cmp = self <=> other
|
---|
15 | if cmp.nil?
|
---|
16 | raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
---|
17 | end
|
---|
18 | cmp < 0
|
---|
19 | end
|
---|
20 |
|
---|
21 | ##
|
---|
22 | # Return true if +self+ is less
|
---|
23 | # than or equal to +other+.
|
---|
24 | # Otherwise return false.
|
---|
25 | #
|
---|
26 | # ISO 15.3.3.2.2
|
---|
27 | def <= other
|
---|
28 | cmp = self <=> other
|
---|
29 | if cmp.nil?
|
---|
30 | raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
---|
31 | end
|
---|
32 | cmp <= 0
|
---|
33 | end
|
---|
34 |
|
---|
35 | ##
|
---|
36 | # Return true if +self+ is equal
|
---|
37 | # to +other+. Otherwise return
|
---|
38 | # false.
|
---|
39 | #
|
---|
40 | # ISO 15.3.3.2.3
|
---|
41 | def == other
|
---|
42 | cmp = self <=> other
|
---|
43 | cmp == 0
|
---|
44 | end
|
---|
45 |
|
---|
46 | ##
|
---|
47 | # Return true if +self+ is greater
|
---|
48 | # than +other+. Otherwise return
|
---|
49 | # false.
|
---|
50 | #
|
---|
51 | # ISO 15.3.3.2.4
|
---|
52 | def > other
|
---|
53 | cmp = self <=> other
|
---|
54 | if cmp.nil?
|
---|
55 | raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
---|
56 | end
|
---|
57 | cmp > 0
|
---|
58 | end
|
---|
59 |
|
---|
60 | ##
|
---|
61 | # Return true if +self+ is greater
|
---|
62 | # than or equal to +other+.
|
---|
63 | # Otherwise return false.
|
---|
64 | #
|
---|
65 | # ISO 15.3.3.2.5
|
---|
66 | def >= other
|
---|
67 | cmp = self <=> other
|
---|
68 | if cmp.nil?
|
---|
69 | raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
|
---|
70 | end
|
---|
71 | cmp >= 0
|
---|
72 | end
|
---|
73 |
|
---|
74 | ##
|
---|
75 | # Return true if +self+ is greater
|
---|
76 | # than or equal to +min+ and
|
---|
77 | # less than or equal to +max+.
|
---|
78 | # Otherwise return false.
|
---|
79 | #
|
---|
80 | # ISO 15.3.3.2.6
|
---|
81 | def between?(min, max)
|
---|
82 | self >= min and self <= max
|
---|
83 | end
|
---|
84 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.