title: Stringify array for eval
body: <p>I'm preparing a string that will be <code>eval</code>'ed. The string will contain a clause built from an existing <code>Array</code>. I have the following:</p>
  
  <pre><code>def stringify(arg)
      return "[ '" + arg.join("', '") + "' ]" if arg.class == Array
      "'#{arg}'"
  end
  
  a = [ 'a', 'b', 'c' ]
  eval_str = 'p ' + stringify(a)
  eval(eval_str)
  </code></pre>
  
  <p>which prints the string <code>["a", "b", "c"]</code>.</p>
  
  <p>Is there a more idiomatic way to do this? <code>Array#to_s</code> doesn't cut it. Is there a way to assign the output from the <code>p</code> method to a variable?</p>
  
  <p>Thanks!</p>