summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-21 16:28:52 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-21 16:28:52 +0000
commitc1c527c290727b3a5d9565f69f1fe3496cbd401b (patch)
tree254ddf8c56ebcc04a82e5036eebaa73a0c792ec5 /lib/set.rb
parentdcea9198a9d80bdf4eeacd9d9e9d883850a4a8d2 (diff)
Fix comparison methods of Set to check if `@hash` is actually comparable
This should fix comparison of rbtree backed SortedSet instances. [Bug #12072] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/set.rb b/lib/set.rb
index caf80aa..05eb3ff 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -237,7 +237,7 @@ class Set
# Returns true if the set is a superset of the given set.
def superset?(set)
case
- when set.instance_of?(self.class)
+ when set.instance_of?(self.class) && @hash.respond_to?(:>=)
@hash >= set.instance_variable_get(:@hash)
when set.is_a?(Set)
size >= set.size && set.all? { |o| include?(o) }
@@ -250,7 +250,7 @@ class Set
# Returns true if the set is a proper superset of the given set.
def proper_superset?(set)
case
- when set.instance_of?(self.class)
+ when set.instance_of?(self.class) && @hash.respond_to?(:>)
@hash > set.instance_variable_get(:@hash)
when set.is_a?(Set)
size > set.size && set.all? { |o| include?(o) }
@@ -263,7 +263,7 @@ class Set
# Returns true if the set is a subset of the given set.
def subset?(set)
case
- when set.instance_of?(self.class)
+ when set.instance_of?(self.class) && @hash.respond_to?(:<=)
@hash <= set.instance_variable_get(:@hash)
when set.is_a?(Set)
size <= set.size && all? { |o| set.include?(o) }
@@ -276,7 +276,7 @@ class Set
# Returns true if the set is a proper subset of the given set.
def proper_subset?(set)
case
- when set.instance_of?(self.class)
+ when set.instance_of?(self.class) && @hash.respond_to?(:<)
@hash < set.instance_variable_get(:@hash)
when set.is_a?(Set)
size < set.size && all? { |o| set.include?(o) }