On Wed, 6 Dec 2000 12:06:04 +0900 David Alan Black <dblack / candle.superlink.net> wrote: > > def get_depths(text) > depths = {} > > indents = text.map do |s| > s.index /\S/ > end > > indents.uniq.sort.each_with_index do |n,x| > depths[n] = x + 1 > end > > (0...text.size) .map do |i| > yield (depths[indents[i]],i) > end > end > > def print_depths(text) > text = text.to_a > get_depths(text) do |d,i| > print "#{d} #{text[i]}" > end > end > I'm inspired by this solution and tried to shape up my previous post([ruby-talk:6835]). This code below seems to work. def get_depths (string) dep_ar = string.collect do |line| line.index /\S/ end string.each do |line| print dep_ar.uniq.sort.index(line.index /\S/) + 1, " #{line}" end end get_depths(<<EOF text1@url1 text2@url2 text3@url3 text3.1 / url3.1 text3.2 / url3.2 text4@url4 text5@url5 text6@url6 text7@url7 text8@url8 text9@url9 EOF )