> I don't really get the question... do you want to do this automatically? > If yes, how should the mapping look like (i.e. what decides that 3 is 1 > level deep, 5 is 4 level deep etc.)? Sorry, my question was missing some important details. 1/ it's array of numbers only 2/ the first number is the base depth 3/ for every number increase a depth of array is added so [1,2,4,2] => [1,[2,[[4]],2]] and [5,5,6] => [5,5,[6]] 4/ and it would be wonderful if it were automatic, by extending the Array class if possible. The image is a kind of opposite of flatten. for now I'm trying with the insert/slice! couple, no cute at all & not really working class Array def depthen base_depth = self[0] range = [0,0] in_flag, out_flag = false, false self.each_index{ |i| if self[i]>base_depth && !in_flag in_flag = true; range[0] = i end if self[i] <= base_depth && !out_flag out_flag = true range[1] = i-1 end } self.insert(range[0], self.slice!(eval(range.join('..'))) ) end end p [2,3,3,5,4,4].depthen => [2,[3,3,5,4,4]] I hope I'm on the good way, but the code is *really* ugly Thank you in advance, Chris. -- Posted via http://www.ruby-forum.com/.