Oh, yes, one should always test after refactoring. Bad me. :-) Better as:

def show_depths (string)
  lens=get_lengths(string)
  depths=get_depths(lens)
  print_depths(string,depths)
end

Better now! :-)

> I'd go for a slightly less refactored version.  Of course,
> it all depends what you think you might want to do on
> other occasions with the methods you've created.  Anyway,
> here's a different approach:

Well, all the extract method is more to show the intention.
Comment-in-the-code. I'm a wannabe XPer. :-) Yours is considerably better, I
would just extract method so each had only one loop (so the method name can
describe what a loop does). My code would probably be refactored to iterated
print_depths, like yours, after I needed another way of printing, or doing
some other thing with the depths. :-)

>    def get_depths(text)
>      depths = {}
>
..........snip............
>        print "#{d} #{text[i]}"
>      end
>    end

Fabio Mascarenhas
mascarenhas / acm.org
mascarenhas / elitenet.com.br