From: Robert Klemme Date: 2007-07-19T17:26:32+09:00 Subject: Re: Array : each_with_index 2007/7/19, Vin Raja : > Thanks All, > > I got the nuance. > > But my problem just got a bit more messier. > have a look down here: > > r = ['KLP','OGN' ] > msg =< Found #{r.length} orders > #{r.map.each_with_index{|v,i| puts "(#{i+1}) #{v}\n" }} > MSG > > puts msg > > This prints: > > >ruby try.rb > (1) KLP > (2) OGN > Found 2 orders > KLPOGN > > >Exit code: 0 > > And this time I also know why, thanks again. > > But what I actually wanted was this sort of output: > > >ruby try.rb > > Found 2 orders > (1) KLP > (2) OGN > > >Exit code: 0 > > Any Help! You are confusing string evaluation with output. You need to remove the puts from the string interpolation or use a different approach. I'd keep things simple and do r = ['KLP','OGN' ] print "found ", r.size, " orders\n" r.each_with_index do |e,i| print " (", i+1, ") ", e, "\n" end robert