From: Robert Klemme Date: 2011-04-05T21:54:33+09:00 Subject: Re: Separate new lines from an output On Tue, Apr 5, 2011 at 12:59 PM, Peter Hickman wrote: > On 5 April 2011 11:38, Leo M. wrote: >> Sorry for being imprecise. >> >> The matter is this : I have 87 files named black1, black2 ...... black >> 87. >> >> I want ruby to print each file with the entire path, so, this is what >> I've written : >> >> i = 1..87 >> >> array = [] >> >> e = i.each {|i| puts ("/R/blackout/black"+i.to_s+"\n")} > > e at this point is an array No, it's a Range. irb(main):001:0> (1..87).each {} => 1..87 irb(main):002:0> (1..87).each {}.class => Range >> array.push e > > You have pushed an array (e) to be the first element of the array (array). He has pushed a Range into the Array. >> puts array.size # => 1 > > So this is correct. You might want to try > > i = 1..87 > > array = i.map {|i| "/R/blackout/black"+i.to_s} > > puts array.size # => 87 If it is just for printing I'd rather (1..87).each {|i| puts "/R/blackout/black#{i}"} 1.upto(87) {|i| puts "/R/blackout/black#{i}"} Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/