2008/3/25, David A. Black <dblack / rubypal.com>:

> Darn, I took you literally :-)
>
>  def t(s)b='*-ox';s.map{|l|c=l.count("\t")
>  (c-1).times{l.sub!(/\t/,' ')}
>  l.sub(/\t/,b[c-1,1])}end
>
>  t(some_string)

You forgot the modulo :

with c = l.count("\t')-1, it gives :

def t(s)b='*-ox';d=b.size;s.map{|l|c=l.count("\t")-1
c.times{l.sub! /\t/,' '}
l.sub /\t/,b[c%d,1]}end

input :

input = <<END_INPUT
foo
\t bar
\t \t baz
\t \t \t hello
\t \t \t \t ciao
\t \t \t \t \t bye
\t \t \t \t \t \t konnichiwa
\t \t world
END_INPUT

James has also forgotten :

bullets = %w[* - o x]
length = bullets.size
input.gsub!(/^(\t ?)+/) do |indent|
  tabs = indent.count("\t") - 1
  "  " * tabs + bullets[tabs%length] + " "
end

   -- Jean-FraníÐis.