> I like Ryan's solution better than the one proposed by Thomas (it seems a > lot cleaner), but I can see that Thomas' solution has an advantage: What > if one were using some kind of templating system where you have a file > which contains embedded Ruby code (like the one I proposed a few days > back), then you actually need to have the names of the variables produced > in the cartesian product code match the names of the variables in the > template file - it looks like the original solution (with a few > modifications) could do that... I think I'll try it. This version allows you to use your own names: def cascade(a, list = [], &block) return list if list.size == a.size a[list.size].each do |item| list << item cascade(a, list, &block) if list.size == a.size block.call(*list) # Expand the list using * end list.slice!(-1) end end a = [(0..20), (43..150), ['z','yz','xyz','xz','zz']] cascade(a) do |width, length, hight| puts "width is: #{width}, length is: #{length}, hight is: #{hight}" end But overall I think Joel VanderWerf's Enumerable tools are probably better thought out and implemented than my version. I'll probably be adding that to my list of useful libraries. Ryan Leavengood