Class: Set
- Inherits:
-
Object
- Object
- Set
- Defined in:
- lib/graph_matching/core_ext/set.rb
Overview
no-doc
Instance Method Summary collapse
-
#disjoint?(set) ⇒ Boolean
Returns true if the set and the given set have no element in common.
-
#intersect?(set) ⇒ Boolean
Returns true if the set and the given set have at least one element in common.
Instance Method Details
#disjoint?(set) ⇒ Boolean
Returns true if the set and the given set have no element in common. This method is the opposite of intersect?. www.ruby-doc.org/stdlib-2.2.0/libdoc/set/rdoc/Set.html#method-i-disjoint-3F
31 32 33 |
# File 'lib/graph_matching/core_ext/set.rb', line 31 def disjoint?(set) !intersect?(set) end |
#intersect?(set) ⇒ Boolean
Returns true if the set and the given set have at least one element in common. www.ruby-doc.org/stdlib-2.2.0/libdoc/set/rdoc/Set.html#method-i-intersect-3F
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/graph_matching/core_ext/set.rb', line 17 def intersect?(set) unless set.is_a?(Set) raise ArgumentError, 'value must be a set' end if size < set.size any? { |o| set.include?(o) } else set.any? { |o| include?(o) } end end |