[前][次][番号順一覧][スレッド一覧]

ruby-changes:48198

From: knu <ko1@a...>
Date: Sun, 22 Oct 2017 01:28:56 +0900 (JST)
Subject: [ruby-changes:48198] knu:r60312 (trunk): Fix comparison methods of Set to check if `@hash` is actually comparable

knu	2017-10-22 01:28:52 +0900 (Sun, 22 Oct 2017)

  New Revision: 60312

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60312

  Log:
    Fix comparison methods of Set to check if `@hash` is actually comparable
    
    This should fix comparison of rbtree backed SortedSet instances.
    [Bug #12072]

  Modified files:
    trunk/lib/set.rb
Index: lib/set.rb
===================================================================
--- lib/set.rb	(revision 60311)
+++ lib/set.rb	(revision 60312)
@@ -237,7 +237,7 @@ class Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L237
   # 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 https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L250
   # 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 https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L263
   # 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 https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L276
   # 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) }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]