title: Code translation, from Python to Ruby
body: <p>I would like to convert a few Python lines on Ruby, from this excellent article signed by Thomas Guest at: <a href="http://wordaligned.org/articles/drawing-chess-positions" rel="nofollow noreferrer">http://wordaligned.org/articles/drawing-chess-positions</a></p>
  
  <p>(note: I'm a really bigger Python noob)</p>
  
  <p>Here is a copy of the original Python version:</p>
  
  <pre><code>def expand_blanks(fen):
      '''Expand the digits in an FEN string into spaces
  
      &gt;&gt;&gt; expand_blanks("rk4q3")
      'rk    q   '
      '''
      def expand(match):
          return ' ' * int(match.group(0))
      return re.compile(r'\d').sub(expand, fen)
  
  def outer_join(sep, ss):
      '''Like string.join, but encloses the result with outer separators.
  
      Example:
      &gt;&gt;&gt; outer_join('|', ['1', '2', '3'])
      '|1|2|3|'
      '''
      return '%s%s%s' % (sep, sep.join(ss), sep)
  
  def ascii_draw_chess_position(fen):
      '''Returns an ASCII picture of pieces on a chessboard.'''
      pieces = expand_blanks(fen).replace('/', '')
      divider = '+-+-+-+-+-+-+-+-+\n'
      rows = ((outer_join('|', pieces[r: r + 8]) + '\n')
              for r in range(0, 8 * 8, 8))
      return outer_join(divider, rows)
  </code></pre>
  
  <p>Usage example:</p>
  
  <pre><code>&gt;&gt;&gt; fen = "r2q1rk1/pp2ppbp/1np2np1/2Q3B1/3PP1b1/2N2N2/PP3PPP/3RKB1R"
  &gt;&gt;&gt; print ascii_draw_chess_position(fen)
  +-+-+-+-+-+-+-+-+
  |r| | |q| |r|k| |
  +-+-+-+-+-+-+-+-+
  |p|p| | |p|p|b|p|
  +-+-+-+-+-+-+-+-+
  | |n|p| | |n|p| |
  +-+-+-+-+-+-+-+-+
  | | |Q| | | |B| |
  +-+-+-+-+-+-+-+-+
  | | | |P|P| |b| |
  +-+-+-+-+-+-+-+-+
  | | |N| | |N| | |
  +-+-+-+-+-+-+-+-+
  |P|P| | | |P|P|P|
  +-+-+-+-+-+-+-+-+
  | | | |R|K|B| |R|
  +-+-+-+-+-+-+-+-+
  </code></pre>
  
  <p>I have trying to do some modifications to convert each line in Ruby... And I wonder if it's bad start :s But I publish it anyway:</p>
  
  <pre><code>def expand_blanks(fen)
    def expand(match)
      return ' ' * int(match.group(0))
    end
  
    # bugged:
    re.compile(r'\d').sub(expand, fen)
  end
  
  def outer_join(sep, ss)
    sep + sep.join(ss) + sep
  end
  
  def ascii_draw_chess_position(fen)
    pieces = expand_blanks(fen).replace('/', '')
    puts pieces.class
    divider = "+-+-+-+-+-+-+-+-+\n"
  
    # bugged lines:
    rows = ((outer_join('|', pieces[r, r + 8]) + '\n')
    for r in range(0, 8 * 8, 8))
      return outer_join(divider, rows)
    end
  end
  
  fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
  puts ascii_draw_chess_position(fen)
  </code></pre>
  
  <p>If you see some lines that I can fix, I would be cool for me. Thank you all.</p>