From f2ece415562cf8525241464c6ff50e3dff6b1c80 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sun, 14 Feb 2016 23:47:39 +0900 Subject: set: fix SortedSet#superset? with rbtree * lib/set.rb (Set#{<,<=,>,>=}): check if the internal @hash has <,<=,>,>= operators. In SortedSet, @hash may be a RBTree, which doesn't have them. --- lib/set.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/set.rb') diff --git a/lib/set.rb b/lib/set.rb index a8f4345f35..d1f99e0eb3 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -219,7 +219,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) } @@ -232,7 +232,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) } @@ -245,7 +245,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) } @@ -258,7 +258,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) } -- cgit v1.2.3