summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/set.rb b/lib/set.rb
index 47fcc3efc7..aec22ef4fe 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -231,6 +231,23 @@ class Set
end
alias < proper_subset?
+ # Returns true if the set and the given set have at least one
+ # element in common.
+ def intersect?(set)
+ set.is_a?(Set) or raise ArgumentError, "value must be a set"
+ if size < set.size
+ any? { |o| set.include?(o) }
+ else
+ set.any? { |o| include?(o) }
+ end
+ end
+
+ # Returns true if the set and the given set have no element in
+ # common. This method is the opposite of +intersect?+.
+ def disjoint?(set)
+ !intersect?(set)
+ end
+
# Calls the given block once for each element in the set, passing
# the element as parameter. Returns an enumerator if no block is
# given.