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,17 +476,16 @@ class Set
def intersect?(set) def intersect?(set)
case set case set
when Set when Set
# nothing
when Array
Set.new(set)
else
raise ArgumentError, "value must be a set or array"
end
if size < set.size if size < set.size
any? { |o| set.include?(o) } any? { |o| set.include?(o) }
else else
set.any? { |o| include?(o) } set.any? { |o| include?(o) }
end end
when Enumerable
set.any? { |o| include?(o) }
else
raise ArgumentError, "value must be enumerable"
end
end end
# Returns true if the set and the given set have no element in # Returns true if the set and the given set have no element in