From: "Jesús Gabriel y Galán" Date: 2009-05-06T19:29:56+09:00 Subject: Re: an array to string in different lines On Wed, May 6, 2009 at 11:25 AM, Sijo Kg wrote: > Hi >   I am collecting errors like object.errors.on(:field)  So some times i > get it like an array > ["error1_message","error2_message"]  or > "error1_message" a string > >   So how can i format this in more than one line  if its an array(or > either case) > example in first case how can i get it like > "error1_message" > "error2_message" A way that works for both cases (array of strings and string): irb(main):002:0> s = ["a", "b"] => ["a", "b"] irb(main):003:0> puts [*s].join("\n") a b => nil irb(main):004:0> s = "a" => "a" irb(main):005:0> puts [*s].join("\n") a Another one: irb(main):004:0> s = "a" => "a" irb(main):006:0> puts [s].flatten.join("\n") a => nil irb(main):007:0> s = ["a", "b"] => ["a", "b"] irb(main):008:0> puts [s].flatten.join("\n") a b Hope this helps, Jesus.