Thank you!

Preliminary testing seems to show that it indeed is faster. I think it 
is understandable since it is doing inline expansion, rather than 
recursion.

Nice use of code generation.

Best regards,

JS

Robert Klemme wrote:
> In case the gateway is broken again:
> 
> I have a shorter alternative; it may be more efficient but you'll have to
> test that for yourself:
> 
> def all_combinations(enum,&bl)
>   pre = ""
>   post = ""
>   middle = []
>   enum.each_with_index do |en,idx|
>     item = "e#{idx}"
>     pre << "enum[" << idx.to_s << "].each {|" << item << "| "
>     middle << item
>     post << "}"
>   end
>   eval(pre << "bl[" << middle.join(",") << "]" << post)
> end
> 
> irb(main):053:0> all_combinations([[1,2,3],%w{a b c d}]) {|*a| p a}
> [1, "a"]
> [1, "b"]
> [1, "c"]
> [1, "d"]
> [2, "a"]
> [2, "b"]
> [2, "c"]
> [2, "d"]
> [3, "a"]
> [3, "b"]
> [3, "c"]
> [3, "d"]
> => [1, 2, 3]
> 
> You can even change this to work with arbitrary Enumerables - this version
> depens on "enum" being an Array.
> 
> Kind regards
> 
>     robert
>