Sha256: 08a661c17cee189b648567098619e31dc1204659006d7c22198fb58396b10ec2
Contents?: true
Size: 860 Bytes
Versions: 9
Compression:
Stored size: 860 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]] # 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
9 entries across 9 versions & 1 rubygems