diff options
author | Jeremy Evans <[email protected]> | 2021-06-15 15:14:54 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2021-07-29 14:18:18 +0900 |
commit | cafa7d897554320b5194f5d71d6a3936f954b484 (patch) | |
tree | a1cbc4123a620573634729e7c59f25a23f0d8d54 /lib/set.rb | |
parent | 571dafdc7f57af067706fbc318a64778f4fc218a (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.rb | 17 |
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 |