title: Reading specific lines from an external file in ruby IO
body: <p>I have this code:</p>
  
  <pre><code>File.foreach("testfile.txt") { |line| print line }
  lines = File.readlines("testfile.txt")
  lines.each { |line| print line }
  </code></pre>
  
  <p>Ex. how could I edit this to <strong>get</strong> a specific line from <code>testfile.txt</code> ?</p>
  
  <pre><code>$text2 = gets("some code to give me text on line 2 from textfile.txt").chomp
  </code></pre>
  
  <p>So, I want to run a program that searches for 4 different variables that are editable by anyone. These will be in a separate file and thus the code will not have to be rewritten in order to change the test for a new set of search cases.</p>
  
  <p>Say I have a document (I suppose text is easiest but am probably wrong) that looks like this:</p>
  
  <pre><code>Tea
  
  Coffee
  
  Hot Chocolate
  
  Cookies
  </code></pre>
  
  <p>That will be all that is in the file. And another file(.rb) pulls these variables and searches for them in Google or whatever. If the code reads in bytes then I wouldn't be able to change the variables to anything longer or shorter.</p>
  
  <p>It would be feasible to have the document say</p>
  
  <pre><code>1:Tea
  
  2:Coffee
  
  3:Hot Chocolate
  
  4:Cookies
  </code></pre>
  
  <p>So long as the code would only pull out the "Tea" or "coffee" and not the preceding number.</p>