From: Nanyang Zhan Date: 2008-01-10T19:16:24+09:00 Subject: Re: method that generate block? > I mean this: > n = vds.size > dss = [] > vds[0].each do |d0| > vds[1].each do |d1| > ... > vds[n].each do |dn| > dss << [d0, d1, ... , dn] > end > ... > end > end OK, now I know I just need a cartesian product method and I've got one from http://www.ruby-forum.com/topic/95519#615075 : def cart_prod( *args ) args.inject([[]]){|old,lst| new = [] lst.each{|e| new += old.map{|c| c.dup << e }} new } end The problem is this method take arrays as argument, how can I pass into only one array as argument? (this one array will contains sub arrays that I want to make a cartesian product from, for example: vds = [[1,2],["a","b"]], how to pass the vds array into the method to get cartesian product of [1,2] and ["a","b"]?) -- Posted via http://www.ruby-forum.com/.