From: Chris White Date: 2011-09-13T23:37:58+09:00 Subject: Re: Iterate Array and (pretty)print > I am trying to iterate through an array, convert the output to a string > and puts that string. > > CODE: > > @hosts = ["test1", "test2", "test3", "test4" > puts @hosts.each { |x| print x + "\n" }.to_s > > CURRENT OUTPUT: > > ["test1", "test2", "test3", "test4"] > > DESIRED OUTPUT: > > However, I want this output to go into an email message, so I'm want to > lose the Square brackets and quotes, so it looks like this (and is a > string): > > test1 > test2 > test3 > > Any ideas? Hi there, In this case I think a simple join would be appropriate: irb(main):001:0> @hosts = ["test1", "test2", "test3", "test4"] => ["test1", "test2", "test3", "test4"] irb(main):002:0> puts @hosts.join("\n") test1 test2 test3 test4 Regards, Chris White http://www.twitter.com/cwgem