<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>

I may be misunderstanding you, but does this look better at all?
```
```
>> a = %w[a b c]
=> ["a", "b", "c"]
>> r = "['#{a.join("', '")}']"
=> "['a', 'b', 'c']"
>> r.class
=> String
```
```
I suppose I'm confused by the need for eval, unless that's a part of something outside of what I see here.