summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-06-15 15:14:54 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-07-29 14:18:18 +0900
commitcafa7d897554320b5194f5d71d6a3936f954b484 (patch)
treea1cbc4123a620573634729e7c59f25a23f0d8d54 /lib/set.rb
parent571dafdc7f57af067706fbc318a64778f4fc218a (diff)
[ruby/set] Allow the use of any enumerable in intersect?/disjoint?
https://github.com/ruby/set/commit/1a73ab9047
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/set.rb b/lib/set.rb
index ec4dabdfca..8ed6e807c7 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -476,16 +476,15 @@ class Set
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