From: Peter Vandenabeele Date: 2011-09-14T00:17:16+09:00 Subject: Re: Iterate Array and (pretty)print --0016e644c538ec1a6404acd40a1c Content-Type: text/plain; charset=UTF-8 On Tue, Sep 13, 2011 at 4:51 PM, Robert Klemme wrote: > On Tue, Sep 13, 2011 at 4:40 PM, Larry Lv wrote: > > hi, > > > > u have output @hosts' elements in the block? why would you add a puts in > > front of it? > > > > u can do it just with Array.join > > > > *puts hosts.join("\n")m* > > You don't even need the join. > > irb(main):001:0> @hosts = ["test1", "test2", "test3", "test4"] > => ["test1", "test2", "test3", "test4"] > irb(main):002:0> puts @hosts > test1 > test2 > test3 > test4 > => nil > irb(main):003:0> > I think this is just an artefact of "puts" and not relevant for the initial problem. If the original posters wants to have it in an e-mail, he will probably will want to interpolate in a template. Using simply the @hosts as is suggested above will then yield this: $ ruby < EOF test1test2test3test4 I think the OP probably needed to use 'map' instead of 'each'. pev@pev-desktop:~/a$ ruby < puts hosts_string > EOF test1 test2 test3 test4 HTH, Peter > > Cheers > > robert > > -- > remember.guy do |as, often| as.you_can - without end > http://blog.rubybestpractices.com/ > > -- Peter Vandenabeele gsm: +32-478-27.40.69 e-mail: peter@vandenabeele.com http://twitter.com/peter_v --0016e644c538ec1a6404acd40a1c--