lib/facet/enumerable/find_collisions.rb in facets-0.9.0 vs lib/facet/enumerable/find_collisions.rb in facets-1.0.0
- old
+ new
@@ -1,40 +1,80 @@
-require 'nano/enumerable/find_collisions.rb'
\ No newline at end of file
+require 'facet/enumerable/commonality'
+
+module Enumerable
+
+ # Like commonality but returns an array if no block is given.
+ #
+ def find_collisions( &blk ) #:yield:
+ if block_given?
+ commonality( &blk )
+ else
+ commonality.values.flatten.uniq
+ end
+ end
+
+end
+
+
+
+# _____ _
+# |_ _|__ ___| |_
+# | |/ _ \/ __| __|
+# | | __/\__ \ |_
+# |_|\___||___/\__|
+#
+=begin test
+
+ require 'test/unit'
+
+ class TCEnumerable < Test::Unit::TestCase
+
+ def test_find_collisions
+ a = [1,2,2,3,3,3]
+ assert_equal( [2,3], a.find_collisions )
+ a = [1,2,2,3,3,3]
+ r = {false=>[1, 2, 2], true=>[3, 3, 3]}
+ assert_equal( r, a.find_collisions { |x| x > 2 } )
+ end
+
+ end
+
+=end