Misc #9331 ยป 0001-Add-examples-to-disjoint-and-intersect.patch
lib/set.rb | ||
---|---|---|
# 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
|
||
... | ... | |
# 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
|