End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Set#intersect?
intersect?(set)
lib/set.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/set.rb, line 480
def intersect?(set)
case set
when Set
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
Returns true if the set and the given enumerable have at least one element in common.
Example
Set[1, 2, 3].intersect? Set[4, 5] #=> false Set[1, 2, 3].intersect? Set[3, 4] #=> true Set[1, 2, 3].intersect? 4..5 #=> false Set[1, 2, 3].intersect? [3, 4] #=> true