title: How to split a string in x equal pieces in ruby
body: <p>I have a string in ruby like this:</p>
  
  <pre><code>str = "AABBCCDDEEFFGGHHIIJJ01020304050607080910"
  # 20 letters and 20 numbers in this case
  </code></pre>
  
  <p>I want to split this in half, which I can do like this:</p>
  
  <pre><code>str[0, str.length/2]
  </code></pre>
  
  <p>or</p>
  
  <pre><code>str.split(0, str.length/2)
  </code></pre>
  
  <p>After that, I need to make arrays with the chars but with length 2 for each element like this:</p>
  
  <pre><code>["AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II", "JJ"],
  [01, 02, 03, 04, 05, 06, 07, 08, 09, 10]
  </code></pre>
  
  <p>The problem is, I can't find a concise way to convert this string. I can do something like this</p>
  
  <pre><code>arr = []
  while str.length &gt; 0 do
    arr &lt;&lt; str[0, 1]
    str[0, 1] = ""
  end
  </code></pre>
  
  <p>but I rather want something like <code>str.split(2)</code>, and the length of the string may change anytime.</p>