From: Chris Morales Date: 2007-11-22T18:28:05+09:00 Subject: Re: How to give depth to arrays? Okay, I made it kinda works, clunky and ugly though... class Array def max max = 0; self.each{ |i| max = i>max ? i : max } max end def min min = 9999; self.each{ |i| min = ibase_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 } to_insert = self.slice!(eval(range.join('..'))) to_insert.depthen if to_insert.max>to_insert.min self.insert( range[0], to_insert ) end end p [2,3,3,5,4,4].depthen => [2,[3,3,[[5],4,4]]] I will be really thankful if anybody could help me improve this monster with nice ruby tricks. Thank you in advance, Chris. -- Posted via http://www.ruby-forum.com/.