On 2010-06-13 11:30:40 -0700, Chuck Brotman said:

> Hi,
> 
> I want to print an array (of strings, mostly) with commas separating the
> elements (so it would look like the result in the irb
> 
> a =[one,two,three]
> printspecial a    # should produce "[one, two, three]" not "onetwothree"
> as it                # currently does
> 
> 
> I tried a.map{|s| s.to_s + ", "
> but this gives me [one, two, three,]
> with an extra comma trailing the last element
> 
> Is there a nice  ruby idiom to do what I want (or to simply produce the
> necessary string for printing?
> 
> Or, do I have to resort to an explicit loop checking for the last
> element and not alter it?

If you want it to "look like the result in the irb", you want Array#inspect.
-- 
Rein Henrichs
http://puppetlabs.com
http://reinh.com