1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/set] Allow the use of any enumerable in intersect?/disjoint?

https://github.com/ruby/set/commit/1a73ab9047
This commit is contained in:
Jeremy Evans 2021-06-15 15:14:54 -07:00 committed by Hiroshi SHIBATA
parent 571dafdc7f
commit cafa7d8975

View file

@ -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