title: How do I print the line number of each line in a string?
body: <p>If I have a string within <code>c1</code>, I can print it in a line by doing:</p>
  
  <pre><code>c1.each_line do |line|
    puts line
  end
  </code></pre>
  
  <p>I want to give the number of each line with each line like this:</p>
  
  <pre><code>c1.each_with_index  do |line, index|
    puts "#{index} #{line}"
  end
  </code></pre>
  
  <p>But that doesn't work on a string.</p>
  
  <p>I tried using <code>$.</code>. When I do that in the above iterator like so:</p>
  
  <pre><code>puts #{$.} #{line}
  </code></pre>
  
  <p>it prints the line number for the last line on each line.</p>
  
  <p>I also tried using <code>lineno</code>, but that seems to work only when I load a file, and not when I use a string.</p>
  
  <p>How do I print or access the line number for each line on a string?</p>