Wow, what are you trying to accomplish? Permutations maybe? I can think of some solutions for dynamical nested each-statments, but I frankly can't think of a problem that I would solve using them. Regards, Florian Gilcher On Oct 18, 2009, at 12:13 AM, Toi Toi wrote: > How can one have a function that uses a dynamic amount of each > statements? Below is the code for level 3. Is there a way to define > this > easily using recursion? I want to avoid having a separate function for > each level. > > def calc nums, level > tmp = [] > nums.each{ |n| tmp.push n > nums.each{ |n2| tmp.push n+n2 > nums.each{ |n3| tmp.push n+n2+n3 > }}} > tmp > end > > puts calc(["0", "1"], 3) > -- > Posted via http://www.ruby-forum.com/. > -- Florian Gilcher smtp: flo / andersground.net jabber: Skade / jabber.ccc.de gpg: 533148E2