summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-28 06:19:19 +0000
committerzzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-28 06:19:19 +0000
commitfa4af4d4cd49be48e92ee7f5fb3588f51924b258 (patch)
tree8ebefde826607e4b5b1afac4650dddeea470260e /lib
parent5d83f5554fac14778e7e738049bb51849ecf28b0 (diff)
* lib/set.rb: [DOC] Add examples for Set#intersect? and Set#disjoint?
Patch by xavier nayrac [Bug #9331] [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/set.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/set.rb b/lib/set.rb
index e30d590c5d..3aebb89376 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -240,6 +240,12 @@ class Set
# Returns true if the set and the given set have at least one
# element in common.
+ #
+ # e.g.:
+ #
+ # require 'set'
+ # Set[1, 2, 3].intersect? Set[4, 5] # => false
+ # Set[1, 2, 3].intersect? Set[3, 4] # => true
def intersect?(set)
set.is_a?(Set) or raise ArgumentError, "value must be a set"
if size < set.size
@@ -251,6 +257,13 @@ class Set
# Returns true if the set and the given set have no element in
# common. This method is the opposite of +intersect?+.
+ #
+ # e.g.:
+ #
+ # require 'set'
+ # Set[1, 2, 3].disjoint? Set[3, 4] # => false
+ # Set[1, 2, 3].disjoint? Set[4, 5] # => true
+
def disjoint?(set)
!intersect?(set)
end