| 1 |
class Module |
| 2 |
|
| 3 |
## |
| 4 |
# call-seq: |
| 5 |
# mod < other -> true, false, or nil |
| 6 |
# |
| 7 |
# Returns true if `mod` is a subclass of `other`. Returns |
| 8 |
# <code>nil</code> if there's no relationship between the two. |
| 9 |
# (Think of the relationship in terms of the class definition: |
| 10 |
# "class A < B" implies "A < B".) |
| 11 |
# |
| 12 |
def <(other) |
| 13 |
if self.equal?(other) |
| 14 |
false |
| 15 |
else |
| 16 |
self <= other |
| 17 |
end |
| 18 |
end |
| 19 |
|
| 20 |
## |
| 21 |
# call-seq: |
| 22 |
# mod <= other -> true, false, or nil |
| 23 |
# |
| 24 |
# Returns true if `mod` is a subclass of `other` or |
| 25 |
# is the same as `other`. Returns |
| 26 |
# <code>nil</code> if there's no relationship between the two. |
| 27 |
# (Think of the relationship in terms of the class definition: |
| 28 |
# "class A < B" implies "A < B".) |
| 29 |
def <=(other) |
| 30 |
raise TypeError, 'compared with non class/module' unless other.is_a?(Module) |
| 31 |
if self.ancestors.include?(other) |
| 32 |
return true |
| 33 |
elsif other.ancestors.include?(self) |
| 34 |
return false |
| 35 |
end |
| 36 |
end |
| 37 |
|
| 38 |
## |
| 39 |
# call-seq: |
| 40 |
# mod > other -> true, false, or nil |
| 41 |
# |
| 42 |
# Returns true if `mod` is an ancestor of `other`. Returns |
| 43 |
# <code>nil</code> if there's no relationship between the two. |
| 44 |
# (Think of the relationship in terms of the class definition: |
| 45 |
# "class A < B" implies "B > A".) |
| 46 |
# |
| 47 |
def >(other) |
| 48 |
if self.equal?(other) |
| 49 |
false |
| 50 |
else |
| 51 |
self >= other |
| 52 |
end |
| 53 |
end |
| 54 |
|
| 55 |
## |
| 56 |
# call-seq: |
| 57 |
# mod >= other -> true, false, or nil |
| 58 |
# |
| 59 |
# Returns true if `mod` is an ancestor of `other`, or the |
| 60 |
# two modules are the same. Returns |
| 61 |
# <code>nil</code> if there's no relationship between the two. |
| 62 |
# (Think of the relationship in terms of the class definition: |
| 63 |
# "class A < B" implies "B > A".) |
| 64 |
# |
| 65 |
def >=(other) |
| 66 |
raise TypeError, 'compared with non class/module' unless other.is_a?(Module) |
| 67 |
return other < self |
| 68 |
end |
| 69 |
|
| 70 |
## |
| 71 |
# call-seq: |
| 72 |
# module <=> other_module -> -1, 0, +1, or nil |
| 73 |
# |
| 74 |
# Comparison---Returns -1, 0, +1 or nil depending on whether `module` |
| 75 |
# includes `other_module`, they are the same, or if `module` is included by |
| 76 |
# `other_module`. |
| 77 |
# |
| 78 |
# Returns `nil` if `module` has no relationship with `other_module`, if |
| 79 |
# `other_module` is not a module, or if the two values are incomparable. |
| 80 |
# |
| 81 |
def <=>(other) |
| 82 |
return 0 if self.equal?(other) |
| 83 |
return nil unless other.is_a?(Module) |
| 84 |
cmp = self < other |
| 85 |
return -1 if cmp |
| 86 |
return 1 unless cmp.nil? |
| 87 |
return nil |
| 88 |
end |
| 89 |
end |