Sha256: 8dbf05fb54f4644add338d245c1c3fdfdb0fd1b472ab6d4502a5935a98d1d681
Contents?: true
Size: 930 Bytes
Versions: 11
Compression:
Stored size: 930 Bytes
Contents
#-- # Cross product adapted from code by Michael Neuman. #++ require 'facet/enumerable/self/cross' module Enumerable # The instance level cross-product method. # # a = [] # [1,2].cross([4,5]){|elem| a << elem } # a #=> [[1, 4],[1, 5],[2, 4],[2, 5]] # #-- # TODO Make a more efficient version just for Array (?) #++ def cross(*enums, &block) Enumerable.cross(self, *enums, &block) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCEnumerable < Test::Unit::TestCase def test_cross a = [1,2,3].cross([4,5,6]) assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a ) a = [] [1,2,3].cross([4,5,6]) {|elem| a << elem } assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a ) end end =end
Version data entries
11 entries across 11 versions & 1 rubygems