title: How to redirect output of Ruby programme to some file
body: <p>I have the following code:</p>
  
  <pre><code>puts "amit"
  puts "ravi"
  </code></pre>
  
  <p>It outputs:</p>
  
  <pre><code>amit
  ravi
  </code></pre>
  
  <p>I would like to redirect <em>amit</em> to one file and <em>ravi</em> to a different file.</p>
  
  <p>Suppose my file name is <code>name.rb</code>. When I am trying like </p>
  
  <pre><code>system("name.rb &gt; #{@filename}")
  </code></pre>
  
  <p>both <em>amit</em> and <em>ravi</em> are redirected to @filename but I want redirection to a different file or first it will redirect to two files of same name but in one file output is <em>amit</em> and in other file of same output is <em>ravi</em>.</p>