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
17
lib/set.rb
17
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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue