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:
parent
571dafdc7f
commit
cafa7d8975
1 changed files with 8 additions and 9 deletions
11
lib/set.rb
11
lib/set.rb
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue