From c1c527c290727b3a5d9565f69f1fe3496cbd401b Mon Sep 17 00:00:00 2001 From: knu Date: Sat, 21 Oct 2017 16:28:52 +0000 Subject: [PATCH] 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 --- lib/set.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/set.rb b/lib/set.rb index caf80aa930..05eb3ffb2a 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) }