title: Capitalize every nth character of each word in a string in Ruby
body: <p>I need to capitalize every 'nth' character for each word in a string (every multiple of 4-th character in this example, so character 4, 8, 12 etc).</p>
  
  <p>I came up with the code below (not very elegant I know!) but it only works for words which <code>length &lt; 8</code>.</p>
  
  <pre><code>'capitalize every fourth character in this string'.split(' ').map do |word|
    word.split('').map.with_index do |l,idx|
    idx % 3 == 0 &amp;&amp; idx &gt; 0 ? word[idx].upcase : l 
    end 
    .join('')
  end 
  .flatten.join(' ')
  </code></pre>
  
  <p>Anybody could show me how to capitalize every 4th character in words which length > 8?</p>
  
  <p>Thanks!</p>