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

ruby-changes:66968

From: Jeremy <ko1@a...>
Date: Thu, 29 Jul 2021 14:50:35 +0900 (JST)
Subject: [ruby-changes:66968] cafa7d8975 (master): [ruby/set] Allow the use of any enumerable in intersect?/disjoint?

https://git.ruby-lang.org/ruby.git/commit/?id=cafa7d8975

From cafa7d897554320b5194f5d71d6a3936f954b484 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Tue, 15 Jun 2021 15:14:54 -0700
Subject: [ruby/set] Allow the use of any enumerable in intersect?/disjoint?

https://github.com/ruby/set/commit/1a73ab9047
---
 lib/set.rb | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/lib/set.rb b/lib/set.rb
index ec4dabd..8ed6e80 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -476,16 +476,15 @@ class Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L476
   def intersect?(set)
     case set
     when Set
-      # nothing
-    when Array
-      Set.new(set)
-    else
-      raise ArgumentError, "value must be a set or array"
-    end
-    if size < set.size
-      any? { |o| set.include?(o) }
-    else
+      if size < set.size
+        any? { |o| set.include?(o) }
+      else
+        set.any? { |o| include?(o) }
+      end
+    when Enumerable
       set.any? { |o| include?(o) }
+    else
+      raise ArgumentError, "value must be enumerable"
     end
   end
 
-- 
cgit v1.1


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

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